List of usage examples for org.hibernate Query setBinary
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBinary(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 ww.j av a2 s . c o 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.db4o.drs.hibernate.impl.Util.java
License:Open Source License
public static ObjectReference getByUUID(Session session, Uuid uuid) { String alias = "objRef"; String uuidPath = alias + "." + ObjectReference.Fields.UUID + "."; String queryString = "from " + "ObjectReference" + " as " + alias + " where " + uuidPath + Uuid.Fields.CREATED + "=?" + " AND " + uuidPath + Uuid.Fields.PROVIDER + "." + ProviderSignature.Fields.SIG + "=?"; Query c = session.createQuery(queryString); c.setLong(0, uuid.getCreated());//from ww w .ja v a2 s.co m c.setBinary(1, uuid.getProvider().getSignature()); final List exisitings = c.list(); int count = exisitings.size(); if (count == 0) return null; else if (count > 1) throw new RuntimeException("Only one ObjectReference should exist"); else { return (ObjectReference) exisitings.get(0); } }
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); }//from www .j a va 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:org.libreplan.business.documents.daos.DocumentDAO.java
License:Open Source License
@Override // @Transactional(propagation = Propagation.REQUIRES_NEW) public int updateContent(Document doc, byte[] content) { if (doc == null) return -1; if (content == null) { return getSession().createSQLQuery("delete from document_content where id=" + doc.getId()) .executeUpdate();//from ww w. j a va2s . c o m } Query query = getSession().createSQLQuery("select id from document_content where id=" + doc.getId()); String iuSql = ""; if (query.uniqueResult() == null) { iuSql = "insert into document_content (content,id) values (?,?) "; query = getSession().createSQLQuery(iuSql); } else { iuSql = "update document_content set content=? where id=?"; query = getSession().createSQLQuery(iuSql); } query.setBinary(0, content); query.setLong(1, doc.getId()); return query.executeUpdate(); }
From source file:org.photovault.imginfo.ImageFileDAOHibernate.java
License:Open Source License
/** Find image files that match a given hash code @param hash The hash code to search for @return ImageFile with matching hash or <code>null</code> if no such file found.//from ww w . ja v a 2s . c om */ public ImageFile findImageFileWithHash(byte[] hash) { Query q = getSession().createQuery("from ImageFile where hash = :hash"); q.setBinary("hash", hash); List<ImageFile> images = q.list(); return images.isEmpty() ? null : images.get(0); }
From source file:org.photovault.imginfo.PhotoInfoDAOHibernate.java
License:Open Source License
public List findPhotosWithOriginalHash(byte[] hash) { Query q = getSession().createQuery("from PhotoInfo where hash = :hash"); q.setBinary("hash", hash); return q.list(); }