List of usage examples for org.hibernate Query setFloat
@Deprecated @SuppressWarnings("unchecked") default Query<R> setFloat(String name, float val)
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 va 2 s .com 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.copyright.common.hibernate.SimpleHibernateDao.java
License:Apache License
/** * ?HQL?Query./*from w ww .jav a 2s . 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.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); }/* ww w.ja v a2s . c om*/ } 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; } }); }
From source file:com.nec.harvest.service.impl.PettyCashServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override/* w ww .j a va 2 s .com*/ public void updatePettyCash(PettyCashBean pettyCashBean) throws ServiceException { if (pettyCashBean == null) { throw new IllegalArgumentException("Petty cash must not be null or empty"); } User user = AuthenticatedUserDetails.getUserPrincipal(); if (user == null) { logger.info("You must login to use this function"); // throw new IllegalArgumentException("You don't have a permission to use this"); } float currentUpdNo = findUpdateNoById(pettyCashBean.getId()); // ?\r\n\r\n????????????? // \r\n?????????? if (currentUpdNo > pettyCashBean.getUpdNo()) { throw new IllegalArgumentException( "?\r\n\r\n?????????????" + "\r\n??????????"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; try { tx = session.beginTransaction(); // StringBuilder sql = new StringBuilder(); sql.append(" UPDATE " + TblConstants.TBL_PETTY_CASH); sql.append(" SET SrDate=:srDate, CtgCode=:ctgCode, Naiyo=:naiyo, Kingaku=:kingaku, Shito=:shito, "); sql.append( " UpdNo=:updNo, TanCode=:tanCode, APInf2=:apInf2, StfCodeU=:stfCodeU, PrdNoU=:prdNoU, RecCkbn=1, TimeU=now()"); sql.append(" WHERE RecID=:recId "); // Query query = pettyCashRepository.getSQLQuery(session, sql.toString()); query.setDate("srDate", pettyCashBean.getDate()); query.setString("ctgCode", pettyCashBean.getItem()); query.setString("naiyo", pettyCashBean.getContent()); query.setDouble("kingaku", pettyCashBean.getAmount()); query.setString("shito", pettyCashBean.getRemark()); query.setFloat("updNo", currentUpdNo + 1); query.setString("tanCode", user.getUsrCode()); query.setString("apInf2", user.getUsrCode()); query.setString("stfCodeU", user.getUsrCode()); try { query.setString("prdNoU", ProductHelper.getProductInfor().getVersion()); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); } query.setString("recId", pettyCashBean.getId()); query.executeUpdate(); tx.commit(); } catch (SQLGrammarException | GenericJDBCException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException("Hibernate runtime exception occur when update a list of petty cashes", ex); } finally { tx = null; HibernateSessionManager.closeSession(session); } }
From source file:com.qcadoo.model.internal.search.SearchQueryImpl.java
License:Open Source License
@Override public void addParameters(final Query query) { for (Map.Entry<String, String> parameter : strings.entrySet()) { query.setString(parameter.getKey(), parameter.getValue()); }//from ww w. ja v a2 s . c o m for (Map.Entry<String, Boolean> parameter : booleans.entrySet()) { query.setBoolean(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Byte> parameter : bytes.entrySet()) { query.setByte(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Short> parameter : shorts.entrySet()) { query.setShort(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Integer> parameter : integers.entrySet()) { query.setInteger(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Long> parameter : longs.entrySet()) { query.setLong(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Float> parameter : floats.entrySet()) { query.setFloat(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Double> parameter : doubles.entrySet()) { query.setDouble(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, BigDecimal> parameter : bigDecimals.entrySet()) { query.setBigDecimal(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : dates.entrySet()) { query.setDate(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : times.entrySet()) { query.setTime(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : timestamps.entrySet()) { query.setTimestamp(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Object> parameter : parameters.entrySet()) { query.setParameter(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Collection<? extends Object>> parametersList : parameterLists.entrySet()) { query.setParameterList(parametersList.getKey(), parametersList.getValue()); } for (Map.Entry<String, Object> parameter : entities.entrySet()) { query.setEntity(parameter.getKey(), parameter.getValue()); } }
From source file:com.square.adherent.noyau.dao.implementations.personne.PersonneDaoImpl.java
License:Open Source License
/** * {@inheritDoc}//from w ww . jav a2 s.c o m */ public List<Long> getListePersonnesNotificationSmsByCriteres(CriteresPersonnesNotificationSmsDto criteres) { // Construction de la requte final StringBuffer requete = new StringBuffer("SELECT distinct l.decompte_assure_uid ") .append("FROM data_decompte l ") .append("INNER JOIN data_option o ON (l.decompte_assure_uid = o.option_personne_uid and o.option_type_uid = :idTypeOptionSms" + " and o.option_top_actif = true) ") .append("WHERE ( ") .append("SELECT sum(l2.decompte_lig_remb_compl) as montant_total FROM data_decompte l2 ") .append("WHERE l2.decompte_origine_uid not in (:listeOriginesDesactivees) ") .append("AND l2.decompte_date_reglement = :datePaiement ") .append("AND l2.decompte_assure_uid = l.decompte_assure_uid ").append(") >= :montantMinimal ") .append("AND decompte_origine_uid not in (:listeOriginesDesactivees) "); final Query query = createSqlQuery(requete.toString()); query.setCalendar("datePaiement", criteres.getDateReglement()); query.setFloat("montantMinimal", criteres.getMontantMinimal()); query.setLong("idTypeOptionSms", adherentMappingService.getIdTypeOptionEnvoiSms()); query.setParameterList("listeOriginesDesactivees", adherentMappingService.getListeOriginesDecomptesExcluesEnvoiSms()); // on mappe les resultats dans des dtos final List<Long> liste = new ArrayList<Long>(); for (Object item : query.list()) { if (item instanceof Long) { liste.add((Long) item); } else if (item instanceof BigInteger) { liste.add(((BigInteger) item).longValue()); } } return liste; }
From source file:EFF.test.Test2.java
public PlazoletaComida identificarPlazoleta(Session s, float gradosLon, float minutosLon, float segundosLon, char orientacionLon, float gradosLat, float minutosLat, float segundosLat, char orientacionLat) { Query q = s.createQuery("from PlazoletaComida where gradosLon=:gradosLon AND " + "minutosLon=:minutosLon AND segundosLon - radio <=:segundosLon AND " + "segundosLon + radio >=:segundosLon AND orientacionLon=:orienteacionLon AND " + "gradosLat=:gradosLat AND minutosLat=:minutosLat " + "AND segundosLat - radio <=:segundosLat AND segundosLat + radio >=:segundosLat " + "AND orientacionLat=:orienteacionLat"); q.setFloat("gradosLon", gradosLon); q.setFloat("minutosLon", minutosLon); q.setFloat("segundosLon", segundosLon); q.setCharacter("orienteacionLon", orientacionLon); q.setFloat("gradosLat", gradosLat); q.setFloat("minutosLat", minutosLat); q.setFloat("segundosLat", segundosLat); q.setCharacter("orienteacionLat", orientacionLat); List<PlazoletaComida> list = q.list(); return list.get(0); }
From source file:org.egov.billsaccounting.services.CreateVoucher.java
License:Open Source License
public void deleteVoucherdetailAndGL(final CVoucherHeader vh) throws SQLException, ApplicationRuntimeException { try {/*from w w w . ja v a2s . c om*/ Query pstmt1 = null; Query pstmt2 = null; Query pstmt3 = null; Query pstmt4 = null; final String glQry = "select id from generalledger where voucherheaderid= ?"; final String glidQry = "select id from generalledgerdetail where generalledgerid= ?"; final String delQry = "delete from EG_REMITTANCE_GLDTL where gldtlid= ?"; final String delQrr = "delete from generalledgerdetail where generalledgerid=?"; final String delgl = " delete from generalledger where voucherheaderid=?"; final String delvh = " delete from voucherdetail where voucherheaderid=?"; pstmt1 = persistenceService.getSession().createSQLQuery(glQry); pstmt1.setFloat(0, vh.getId()); final List<Object[]> rs = pstmt1.list(); List<Object[]> rs1 = null; boolean delete = false; while (rs != null && rs.size() > 0) { pstmt2 = persistenceService.getSession().createSQLQuery(glidQry); pstmt2.setLong(0, Long.parseLong(rs.get(1).toString())); rs1 = pstmt2.list(); while (rs1 != null && rs1.size() > 0) { delete = true; pstmt3 = persistenceService.getSession().createSQLQuery(delQry); pstmt3.setLong(0, Long.parseLong(rs1.get(1).toString())); pstmt3.executeUpdate(); } if (delete) { pstmt4 = persistenceService.getSession().createSQLQuery(delQrr); pstmt4.setLong(0, Long.parseLong(rs1.get(1).toString())); pstmt4.executeUpdate(); } } pstmt1 = persistenceService.getSession().createSQLQuery(delgl); pstmt1.setLong(0, vh.getId()); pstmt1.executeUpdate(); pstmt1 = persistenceService.getSession().createSQLQuery(delvh); pstmt1.setLong(0, vh.getId()); pstmt1.executeUpdate(); } catch (final Exception e) { LOGGER.error("Inside exception deleteVoucherdetailAndGL" + e.getMessage()); throw new ApplicationRuntimeException(e.getMessage()); } }