List of usage examples for org.hibernate Query setByte
@Deprecated @SuppressWarnings("unchecked") default Query<R> setByte(String name, byte 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 w w. j a va 2 s . c om 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.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 . j a v a 2s . 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; } }); }
From source file:com.netsteadfast.greenstep.base.dao.BaseDAO.java
License:Apache License
/** * for public QueryResult getList... doInHibernate * @param query JPA-Style : from TB_ACCOUNT where account = ?0 * @param position JPA-Style : "0", "1" ..... * @param params/*w ww . j av a 2 s. com*/ */ @SuppressWarnings("rawtypes") private void setQueryParams(Query query, String position, Object params) { if (params instanceof java.lang.String) { query.setString(position, (java.lang.String) params); return; } if (params instanceof java.lang.Character) { query.setCharacter(position, (java.lang.Character) params); return; } if (params instanceof java.lang.Double) { query.setDouble(position, (java.lang.Double) params); return; } if (params instanceof java.lang.Byte) { query.setByte(position, (java.lang.Byte) params); return; } if (params instanceof java.lang.Integer) { query.setInteger(position, (java.lang.Integer) params); return; } if (params instanceof java.lang.Long) { query.setLong(position, (java.lang.Long) params); return; } if (params instanceof java.lang.Boolean) { query.setBoolean(position, (java.lang.Boolean) params); return; } if (params instanceof java.math.BigDecimal) { query.setBigDecimal(position, (java.math.BigDecimal) params); return; } if (params instanceof java.util.Date) { query.setDate(position, (java.util.Date) params); return; } if (params instanceof java.util.List) { List listParams = (List) params; this.setQueryParamsOfList(query, position, listParams); return; } }
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 w w w . j a v a 2s.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()); } }