Example usage for org.hibernate Query setParameterList

List of usage examples for org.hibernate Query setParameterList

Introduction

In this page you can find the example usage for org.hibernate Query setParameterList.

Prototype

Query<R> setParameterList(int position, Object[] values);

Source Link

Usage

From source file:net.firejack.platform.core.store.lookup.LookupStore.java

License:Apache License

@Transactional(readOnly = true)
public List<SearchModel> search(final String term, final String prefix, final RegistryNodeType type,
        final Paging paging) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public List<SearchModel> doInHibernate(Session session) throws HibernateException, SQLException {
            List<String> excludable = RegistryNodeType.excludable();

            boolean existPrefix = StringUtils.isNotEmpty(prefix);
            boolean existType = type != null;
            boolean existExcludable = !excludable.isEmpty();

            StringBuilder sql = buildSearchQuery(paging, existPrefix, existType, false, existExcludable);
            Query query = session.createSQLQuery(sql.toString());

            query.setParameter("term", "%" + term + "%");
            if (!excludable.isEmpty()) {
                query.setParameterList("excludable", excludable);
            }/*from  ww w .  j av  a2 s.c o  m*/
            if (existPrefix) {
                query.setParameter("prefix", prefix + "%");
            }
            if (existType) {
                query.setParameter("type", type.getType());
            }
            if (paging != null && paging.getOffset() > 0) {
                query.setFirstResult(paging.getOffset());
            }
            if (paging != null && paging.getLimit() > 0) {
                query.setMaxResults(paging.getLimit());
            }

            List<SearchModel> list = new ArrayList<SearchModel>();
            List<Object[]> result = query.list();
            for (Object[] objects : result) {
                list.add(new SearchModel(objects));
            }
            return list;
        }
    });
}

From source file:net.firejack.platform.core.store.lookup.LookupStore.java

License:Apache License

@Transactional(readOnly = true)
public Integer searchCount(final String term, final String prefix, final RegistryNodeType type) {
    return getHibernateTemplate().execute(new HibernateCallback<Integer>() {
        public Integer doInHibernate(Session session) throws HibernateException, SQLException {
            List<String> excludable = RegistryNodeType.excludable();

            boolean existPrefix = StringUtils.isNotEmpty(prefix);
            boolean existType = type != null;
            boolean existExcludable = !excludable.isEmpty();

            StringBuilder sql = buildSearchQuery(null, existPrefix, existType, true, existExcludable);
            Query query = session.createSQLQuery(sql.toString());

            query.setParameter("term", "%" + term + "%");
            if (existExcludable) {
                query.setParameterList("excludable", excludable);
            }//from   w w w. j a v  a 2 s. c o  m
            if (existPrefix) {
                query.setParameter("prefix", prefix + "%");
            }
            if (existType) {
                query.setParameter("type", type.getType());
            }

            List<Number> result = query.list();
            if (result.isEmpty()) {
                return 0;
            } else {
                return result.get(0).intValue();
            }
        }
    });
}

From source file:net.malta.model.crud.AttachmentManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {/*from ww w  .j  av a  2s. c o  m*/
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.AttachmentImpl 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.CarriageManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {//  ww  w  . j a  v a 2s.c  om
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.CarriageImpl 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.CategoryManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {/* w w  w  .  j a va 2s .c om*/
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.CategoryImpl 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.ChoiseManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {/* w w  w  .  ja v  a2  s .co m*/
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.ChoiseImpl 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.DbFileManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {/* w w w  .j a  v  a2s .com*/
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.DbFileImpl 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.DeliveryAddressChoiseManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {//from  w  w w.ja  v a 2  s .  c  om
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.DeliveryAddressChoiseImpl 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.DeliveryAddressManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {//from  w  w w  .  j a v  a  2  s .  c  o  m
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.DeliveryAddressImpl 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.GiftCardManageableDaoBase.java

public void delete(java.lang.Integer[] ids) {
    final Session session = getSession(false);
    try {/* w  w w.j ava2 s  .c om*/
        final org.hibernate.Query queryObject = session
                .createQuery("delete net.malta.model.GiftCardImpl where id in (:ids)");
        queryObject.setParameterList("ids", ids);
        queryObject.executeUpdate();
    } catch (org.hibernate.HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}