List of usage examples for org.hibernate Query setDouble
@Deprecated @SuppressWarnings("unchecked") default Query<R> setDouble(String name, double val)
From source file:br.com.hslife.imobiliaria.dao.impl.HibernateGenericDao.java
License:Open Source License
public List queryList(String namedQuery, Map<String, Object> params) { HibernateUtility.getSession().clear(); Query query = HibernateUtility.getSession().getNamedQuery(namedQuery); for (String key : params.keySet()) { if (params.get(key) instanceof String) { query.setString(key, (String) params.get(key)); }/*from w w w . j av a 2s . c om*/ if (params.get(key) instanceof Long) { query.setLong(key, (Long) params.get(key)); } if (params.get(key) instanceof Integer) { query.setInteger(key, (Integer) params.get(key)); } if (params.get(key) instanceof Boolean) { query.setBoolean(key, (Boolean) params.get(key)); } if (params.get(key) instanceof Double) { query.setDouble(key, (Double) params.get(key)); } if (params.get(key) instanceof Date) { query.setDate(key, (Date) params.get(key)); } } return query.list(); }
From source file:br.com.hslife.imobiliaria.dao.impl.HibernateGenericDao.java
License:Open Source License
public void queryNoResult(String namedQuery, Map<String, Object> params) { Query query = HibernateUtility.getSession().getNamedQuery(namedQuery); for (String key : params.keySet()) { if (params.get(key) instanceof String) { query.setString(key, (String) params.get(key)); }//from w ww . j a va 2 s.co m if (params.get(key) instanceof Long) { query.setLong(key, (Long) params.get(key)); } if (params.get(key) instanceof Integer) { query.setInteger(key, (Integer) params.get(key)); } if (params.get(key) instanceof Boolean) { query.setBoolean(key, (Boolean) params.get(key)); } if (params.get(key) instanceof Double) { query.setDouble(key, (Double) params.get(key)); } if (params.get(key) instanceof Date) { query.setDate(key, (Date) params.get(key)); } } query.executeUpdate(); HibernateUtility.getSession().flush(); HibernateUtility.getSession().clear(); }
From source file:br.com.hslife.imobiliaria.dao.impl.HibernateGenericDao.java
License:Open Source License
public Object queryUnique(String namedQuery, Map<String, Object> params) { HibernateUtility.getSession().clear(); Query query = HibernateUtility.getSession().getNamedQuery(namedQuery); for (String key : params.keySet()) { if (params.get(key) instanceof String) { query.setString(key, (String) params.get(key)); }//from w ww. j a v a2 s . com if (params.get(key) instanceof Long) { query.setLong(key, (Long) params.get(key)); } if (params.get(key) instanceof Integer) { query.setInteger(key, (Integer) params.get(key)); } if (params.get(key) instanceof Boolean) { query.setBoolean(key, (Boolean) params.get(key)); } if (params.get(key) instanceof Double) { query.setDouble(key, (Double) params.get(key)); } if (params.get(key) instanceof Date) { query.setDate(key, (Date) params.get(key)); } } return query.uniqueResult(); }
From source file:com.bancomat.springmvc.dao.UtenteDao.java
public static int updateSaldo(int id, double saldo) { session = HibernateUtil.getSessionFactory().openSession(); Transaction tsc = session.beginTransaction(); String updateQuery = "update Utente u set u.saldo = :saldo where idUtente = :id"; Query qry = session.createQuery(updateQuery); qry.setDouble("saldo", saldo); qry.setInteger("id", id); int result = qry.executeUpdate(); session.getTransaction().commit();// w ww .ja v a2s. c o m return result; }
From source file:com.cloud.bridge.util.QueryHelper.java
License:Open Source License
public static void bindParameters(Query query, Object[] params) { int pos = 0;/*from w ww . j a v a 2s . co m*/ if (params != null && params.length > 0) { for (Object param : params) { if (param instanceof Byte) query.setByte(pos++, ((Byte) param).byteValue()); else if (param instanceof Short) query.setShort(pos++, ((Short) param).shortValue()); else if (param instanceof Integer) query.setInteger(pos++, ((Integer) param).intValue()); else if (param instanceof Long) query.setLong(pos++, ((Long) param).longValue()); else if (param instanceof Float) query.setFloat(pos++, ((Float) param).floatValue()); else if (param instanceof Double) query.setDouble(pos++, ((Double) param).doubleValue()); else if (param instanceof Boolean) query.setBoolean(pos++, ((Boolean) param).booleanValue()); else if (param instanceof Character) query.setCharacter(pos++, ((Character) param).charValue()); else if (param instanceof Date) query.setDate(pos++, (Date) param); else if (param instanceof Calendar) query.setCalendar(pos++, (Calendar) param); else if (param instanceof CalendarDateParam) query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue()); else if (param instanceof TimestampParam) query.setTimestamp(pos++, ((TimestampParam) param).timestampValue()); else if (param instanceof TimeParam) query.setTime(pos++, ((TimeParam) param).timeValue()); else if (param instanceof String) query.setString(pos++, (String) param); else if (param instanceof TextParam) query.setText(pos++, ((TextParam) param).textValue()); else if (param instanceof byte[]) query.setBinary(pos++, (byte[]) param); else if (param instanceof BigDecimal) query.setBigDecimal(pos++, (BigDecimal) param); else if (param instanceof BigInteger) query.setBigInteger(pos++, (BigInteger) param); else if (param instanceof Locale) query.setLocale(pos++, (Locale) param); else if (param instanceof EntityParam) query.setEntity(pos++, ((EntityParam) param).entityValue()); else if (param instanceof Serializable) query.setSerializable(pos++, (Serializable) param); else query.setEntity(pos++, param); } } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public void updatePosition(PostPositionRequest req, long userId, Position user) { try {// w w w .ja va 2 s . co m if (PositionHelper.distFrom(req.getLat(), req.getLon(), user.getLat(), user.getLon()) > 5000) { String hql = "update Position user set user.lon=?, user.lat=?, user.positionTime=?, user.city=?, " + "user.lastEffectLon=?, user.lastEffectLat=?, user.lastPositionTime=?, user.lastEffectCity=?, " + "user.updateTime=? "; hql += " where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); int i = 0; query.setDouble(i, req.getLon()); query.setDouble(++i, req.getLat()); query.setLong(++i, System.currentTimeMillis()); query.setInteger(++i, req.getCityId()); query.setDouble(++i, req.getLon()); query.setDouble(++i, req.getLat()); query.setLong(++i, System.currentTimeMillis()); query.setInteger(++i, req.getCityId()); query.setLong(++i, System.currentTimeMillis()); query.setLong(++i, userId); query.executeUpdate(); } else { String hql = "update Position user set user.lon=?, user.lat=?, user.positionTime=?, user.city=?, user.updateTime=? "; hql += " where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); int i = 0; query.setDouble(i, req.getLon()); query.setDouble(++i, req.getLat()); query.setLong(++i, System.currentTimeMillis()); query.setInteger(++i, req.getCityId()); query.setLong(++i, System.currentTimeMillis()); query.setLong(++i, userId); query.executeUpdate(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
public List<Object> searchDriverList(SearchDriverRequest req) { /**/* w ww . j a v a2 s. c om*/ * */ long possitionTime = System.currentTimeMillis() - TimeUtils.DAY * 14; Query query = null; StringBuffer querysql = new StringBuffer(""); String truckLengthCondition = req.getTruckLength() <= 0d ? "" : "and p.truck_length=:truckLength"; String sqlTem = "(select u.user_id as userId,p.picture as picture,p.user_name as userName,u.telephone as telephone,p.truck_length as truckLength,p.truck_load as truckLoad,p.truck_type as truckType,p.number as number,u.is_authenticate as isAuthenticate,u.create_time as updateTime,p.order_count as orderCount,u.city as cityId,abs(u.city-:start) as sortFlag from users u, profiles p, %s sub, search_conditions sc where sub.user_id=u.user_id and u.user_id=p.user_id and p.user_type=1 and sub.search_id=sc.search_id and u.telephone>13000000000 " + truckLengthCondition + " and sub.push_subscribe=1 and u.push_subscribe=1 and u.type=1 and sub.type>0 and (sc.end=:end or sc.end=:endFather) and (sc.start=:start or sc.start=:startFather) and u.update_time>:before and u.update_time<:after and u.update_time>:possitionTime)"; for (int i = 0; i < Constant.SHARD_TABLE_SUBSCRIBE.length; i++) { if (i == 0) { querysql.append("select t.* from (" + String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + " union all "); } else if (i == Constant.SHARD_TABLE_SUBSCRIBE.length - 1) { querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + ") t group by t.userId order by t.sortFlag asc,t.updateTime desc");//,t.orderCount desc } else { querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + " union all "); } } query = sessionFactory.getCurrentSession().createSQLQuery(querysql.toString()) .addScalar("userId", StandardBasicTypes.LONG).addScalar("picture", StandardBasicTypes.STRING) .addScalar("userName", StandardBasicTypes.STRING).addScalar("telephone", StandardBasicTypes.STRING) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("truckLoad", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER).addScalar("number", StandardBasicTypes.STRING) .addScalar("isAuthenticate", StandardBasicTypes.INTEGER) .addScalar("updateTime", StandardBasicTypes.LONG) .addScalar("orderCount", StandardBasicTypes.INTEGER).addScalar("cityId", StandardBasicTypes.INTEGER) .setResultTransformer(Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class)); if (req.getTruckLength() > 0) { query.setDouble("truckLength", req.getTruckLength()); } query.setInteger("end", req.getEnd()).setInteger("endFather", req.getEndFather()) .setInteger("start", req.getStart()).setInteger("startFather", req.getStartFather()) .setLong("before", req.getBefore()).setLong("after", req.getAfter()) .setLong("possitionTime", possitionTime); query.setMaxResults(req.getCount()); @SuppressWarnings("unchecked") List<Object> all = query.list(); return all; }
From source file:com.copyright.common.hibernate.SimpleHibernateDao.java
License:Apache License
/** * ?HQL?Query.//from w w w. ja v a 2 s. c om * * ?find()T,?T. * * @param values ????,?. */ public Query createQuery(final String queryString, final Object... values) { Assert.hasText(queryString, "queryString?"); Query query = getSession().createQuery(queryString); if (values != null && values.length > 0) { if (values[0] instanceof Hashtable) { Hashtable temp = (Hashtable) values[0]; query = setParamHash(query, temp); } else { if (values[0] instanceof List) { List temp = (List) values[0]; int size = temp.size(); for (int i = 0; i < size; i++) { Object param = temp.get(i); //query.setParameter(i,values[i]); if (param instanceof String) { String paramValue = (String) param; query.setString(i, paramValue); } else { if (param instanceof Integer) { Integer paramValue = (Integer) param; query.setInteger(i, paramValue.intValue()); } else { if (param instanceof Long) { Long paramValue = (Long) param; query.setLong(i, paramValue.longValue()); } else { if (param instanceof Double) { Double paramValue = (Double) param; query.setDouble(i, paramValue.doubleValue()); } else { if (param instanceof Float) { Float paramValue = (Float) param; query.setFloat(i, paramValue.floatValue()); } } } } } } } else { for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); } } } } return query; }
From source file:com.copyright.common.hibernate.SimpleHibernateDao.java
License:Apache License
/** * //from w w w .j a v a 2 s. c o m * @param query * @param values * @return */ private Query setParamHash(Query query, Hashtable<String, ?> values) { if (values != null) { //query.setProperties(values); Enumeration parameterNames = values.keys(); while (parameterNames.hasMoreElements() == true) { String pName = (String) parameterNames.nextElement(); Object param = values.get(pName); if (param instanceof String) { String paramValue = (String) param; query.setString(pName, paramValue); } else { if (param instanceof Integer) { Integer paramValue = (Integer) param; query.setInteger(pName, paramValue.intValue()); } else { if (param instanceof Double) { Double paramValue = (Double) param; query.setDouble(pName, paramValue.doubleValue()); } } } } } return query; }
From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java
License:Open Source License
public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters, final boolean cacheable) { return executeListResult(ContentKey.class, new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query compiled = session.createQuery(hqlQuery); compiled.setCacheable(cacheable); for (String key : parameters.keySet()) { Object value = parameters.get(key); if (value instanceof Date) { compiled.setTimestamp(key, (Date) value); } else if (value instanceof String) { compiled.setString(key, (String) value); } else if (value instanceof Boolean) { compiled.setBoolean(key, (Boolean) value); } else if (value instanceof Long) { compiled.setLong(key, (Long) value); } else if (value instanceof Integer) { compiled.setInteger(key, (Integer) value); } else if (value instanceof Byte) { compiled.setByte(key, (Byte) value); } else if (value instanceof byte[]) { compiled.setBinary(key, (byte[]) value); } else if (value instanceof Float) { compiled.setFloat(key, (Float) value); } else if (value instanceof Double) { compiled.setDouble(key, (Double) value); } else if (value instanceof BigDecimal) { compiled.setBigDecimal(key, (BigDecimal) value); } else if (value instanceof Short) { compiled.setShort(key, (Short) value); } else if (value instanceof BigInteger) { compiled.setBigInteger(key, (BigInteger) value); } else if (value instanceof Character) { compiled.setCharacter(key, (Character) value); } else { compiled.setParameter(key, value); }/*www . ja v a 2 s . c o m*/ } final List result = compiled.list(); LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size()); for (Object value : result) { if (value instanceof ContentKey) { distinctContentKeySet.add((ContentKey) value); } else { Object[] valueList = (Object[]) value; distinctContentKeySet.add(((ContentKey) valueList[0])); } } List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size()); distinctContentKeyList.addAll(distinctContentKeySet); return distinctContentKeyList; } }); }