List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:net.malta.model.crud.ItemManageableDaoBase.java
public void delete(java.lang.Integer[] ids) { final Session session = getSession(false); try {/*from w ww. j a v a 2s . co m*/ final org.hibernate.Query queryObject = session .createQuery("delete net.malta.model.ItemImpl where id in (:ids)"); queryObject.setParameterList("ids", ids); queryObject.executeUpdate(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:net.malta.model.crud.PaymentMethodManageableDaoBase.java
public void delete(java.lang.Integer[] ids) { final Session session = getSession(false); try {/*from w w w .j a v a2s .c o m*/ final org.hibernate.Query queryObject = session .createQuery("delete net.malta.model.PaymentMethodImpl where id in (:ids)"); queryObject.setParameterList("ids", ids); queryObject.executeUpdate(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:net.malta.model.crud.PrefectureManageableDaoBase.java
public void delete(java.lang.Integer[] ids) { final Session session = getSession(false); try {/*ww w .j a va 2s.c om*/ final org.hibernate.Query queryObject = session .createQuery("delete net.malta.model.PrefectureImpl where id in (:ids)"); queryObject.setParameterList("ids", ids); queryObject.executeUpdate(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:net.malta.model.crud.ProductManageableDaoBase.java
public void delete(java.lang.Integer[] ids) { final Session session = getSession(false); try {/* ww w. jav a2s. c om*/ final org.hibernate.Query queryObject = session .createQuery("delete net.malta.model.ProductImpl where id in (:ids)"); queryObject.setParameterList("ids", ids); queryObject.executeUpdate(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:net.malta.model.crud.PublicUserManageableDaoBase.java
public void delete(java.lang.Integer[] ids) { final Session session = getSession(false); try {/*ww w .j a v a 2 s .co m*/ final org.hibernate.Query queryObject = session .createQuery("delete net.malta.model.PublicUserImpl where id in (:ids)"); queryObject.setParameterList("ids", ids); queryObject.executeUpdate(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:net.malta.model.crud.PurchaseManageableDaoBase.java
public void delete(java.lang.Integer[] ids) { final Session session = getSession(false); try {//ww w . ja va 2s . co m final org.hibernate.Query queryObject = session .createQuery("delete net.malta.model.PurchaseImpl where id in (:ids)"); queryObject.setParameterList("ids", ids); queryObject.executeUpdate(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:net.malta.model.crud.StaticDataManageableDaoBase.java
public void delete(java.lang.Integer[] ids) { final Session session = getSession(false); try {/*from w w w .ja v a 2s .co m*/ final org.hibernate.Query queryObject = session .createQuery("delete net.malta.model.StaticDataImpl where id in (:ids)"); queryObject.setParameterList("ids", ids); queryObject.executeUpdate(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:net.mlw.vlh.adapter.hibernate3.util.StatementBuilder.java
License:Open Source License
/** * Usage of filters: {key} -> :keyName add to query's parameter map keyValue * [key] -> keyValue// www. j a v a2 s . co m * * @param hql * @param whereClause * @return Query for ordinary list * @throws HibernateException * @throws ParseException */ public Query generate(Session session, StringBuffer hql, Map whereClause, boolean isRemoveEmptyStrings) throws HibernateException, ParseException { if (whereClause == null) { whereClause = Collections.EMPTY_MAP; } Map arguments = new HashMap(); // Include or exclude the filters. for (int i = 0, end = 0, start; ((start = hql.toString().indexOf("/~", end)) >= 0); i++) { end = hql.toString().indexOf("~/", start); String key = hql.substring(start + 2, hql.indexOf(":", start)); Object value = whereClause.get(key); if (isValuePopulated(value, isRemoveEmptyStrings)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("The filter key=[" + key + "] with the value=[" + value + "] is accepted by the hql preprocesor"); } hql.replace(start, end + 2, hql.substring(hql.indexOf(":", start) + 1, end)); } else { if (LOGGER.isInfoEnabled()) { LOGGER.info("The filter key=[" + key + "] is removed from the query by the hql preprocesor."); } hql.replace(start, end + 2, ""); } end -= start; } // Replace any [key] with the value in the whereClause Map. for (int i = 0, end = 0, start; ((start = hql.toString().indexOf('[', end)) >= 0); i++) { end = hql.toString().indexOf(']', start); String key = hql.substring(start + 1, end); Object value = whereClause.get(key); hql.replace(start, end + 1, (value == null) ? "" : value.toString()); end -= (key.length() + 2); } // Replace any "{key}" with the value in the whereClause Map, // then placing the value in the partameters list. for (int i = 0, end = 0, start; ((start = hql.toString().indexOf('{', end)) >= 0); i++) { end = hql.toString().indexOf('}', start); String key = hql.substring(start + 1, end); Object value = whereClause.get(key); if (value == null) { throw new NullPointerException("Property '" + key + "' was not provided."); } arguments.put(key, value); hql.replace(start, end + 1, ":" + key); end -= (key.length() + 2); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("The final query is " + hql); } Query query = session.createQuery(hql.toString()); // Now set all the patameters on the statement. if (setters == null) { for (Iterator keys = arguments.keySet().iterator(); keys.hasNext();) { String key = (String) keys.next(); Object value = arguments.get(key); if (value instanceof List) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting a paremeterList to the query."); } query.setParameterList(key, ((List) value).toArray()); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Using the default setter for key=[" + key + "] with the value=[" + value + "]"); } getDefaultSetter().set(query, key, value); } } } else { for (Iterator keys = arguments.keySet().iterator(); keys.hasNext();) { String key = (String) keys.next(); Object value = arguments.get(key); getSetter(key).set(query, key, value); } } return query; }
From source file:nl.strohalm.cyclos.utils.hibernate.HibernateQueryHandler.java
License:Open Source License
/** * Sets the query bind named parameters/* w w w . j a va 2 s.co m*/ */ public void setQueryParameters(final Query query, final Object parameters) { if (parameters != null) { if (parameters instanceof Map<?, ?>) { final Map<?, ?> map = (Map<?, ?>) parameters; final String[] paramNames = query.getNamedParameters(); for (final String param : paramNames) { final Object value = map.get(param); if (value instanceof Collection<?>) { final Collection<Object> values = new ArrayList<Object>(((Collection<?>) value).size()); for (final Object object : (Collection<?>) value) { if (object instanceof EntityReference) { values.add(fetchDao.fetch((Entity) object)); } else { values.add(object); } } query.setParameterList(param, values); } else if (value instanceof EntityReference) { query.setParameter(param, fetchDao.fetch((Entity) value)); } else { query.setParameter(param, value); } } } else { query.setProperties(parameters); } } }
From source file:ome.services.delete.DeleteBean.java
License:Open Source License
@RolesAllowed("user") public void deletePlate(final long plateId) { Plate p = iQuery.get(Plate.class, plateId); throwSecurityViolationIfNotAllowed(p); sec.runAsAdmin(new AdminAction() { public void runAsAdmin() { final List<Object[]> imagesOnPlate = iQuery.projection(PLATEIMAGES_QUERY, new Parameters().addId(plateId)); final Session session = sf.getSession(); final StringBuilder sb = new StringBuilder(); sb.append("Delete for plate "); sb.append(plateId);// ww w .j a va 2 s . co m sb.append(" : "); Query q; // reused. int count; // reused if (imagesOnPlate.size() > 0) { Set<Long> imageIdsForPlate = new HashSet<Long>(); for (Object[] objs : imagesOnPlate) { imageIdsForPlate.add((Long) objs[0]); } sb.append(imageIdsForPlate.size()); sb.append(" Image(s); "); // Samples q = session.createQuery("delete WellSampleAnnotationLink " + "where parent.id in (select id from WellSample " + "where image.id in (:ids) )"); q.setParameterList("ids", imageIdsForPlate); count = q.executeUpdate(); sb.append(count); sb.append(" WellSampleAnnotationLink(s); "); q = session.createQuery("delete WellSample " + "where image.id in (:ids)"); q.setParameterList("ids", imageIdsForPlate); count = q.executeUpdate(); sb.append(count); sb.append(" WellSample(s); "); // Images deleteImages(imageIdsForPlate, true); } // Well q = session.createQuery("delete WellAnnotationLink where parent.id in " + "(select id from Well where plate.id = :id)"); q.setParameter("id", plateId); count = q.executeUpdate(); sb.append(count); sb.append(" WellAnnotationLink(s);"); q = session.createQuery("delete Well where plate.id = :id"); q.setParameter("id", plateId); count = q.executeUpdate(); sb.append(count); sb.append(" Well(s);"); // Plate annotations q = session.createQuery("delete PlateAnnotationLink where parent.id = :id"); q.setParameter("id", plateId); count = q.executeUpdate(); sb.append(count); sb.append(" PlateAnnotationLink(s);"); // Screen links q = session.createQuery("delete ScreenPlateLink where child.id = :id"); q.setParameter("id", plateId); count = q.executeUpdate(); sb.append(count); sb.append(" ScreenPlateLink(s);"); // Finally, the plate. q = session.createQuery("delete Plate where id = :id"); q.setParameter("id", plateId); q.executeUpdate(); iUpdate.flush(); log.info(sb.toString()); } }); }