List of usage examples for org.hibernate SQLQuery setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(int position, int val)
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractDAO.java
License:Apache License
/** * Executes given <var>sql</var>. * <p>/*from w w w . jav a2s . c om*/ * Should be an <code>INSERT</code> or <code>UPDATE</code> statement. * </p> */ protected final void executeUpdate(final String sql, final Serializable... parameters) { getHibernateTemplate().execute(new HibernateCallback() { // // HibernateCallback // public final Object doInHibernate(final Session session) throws HibernateException, SQLException { final SQLQuery sqlQuery = session.createSQLQuery(sql); for (int i = 0; i < parameters.length; i++) { Serializable parameter = parameters[i]; if (parameter instanceof Long) { sqlQuery.setLong(i, (Long) parameter); } else if (parameter instanceof Integer) { sqlQuery.setInteger(i, (Integer) parameter); } else if (parameter instanceof Character) { sqlQuery.setCharacter(i, (Character) parameter); } else if (parameter instanceof Date) { sqlQuery.setDate(i, (Date) parameter); } else { sqlQuery.setSerializable(i, parameter); } } sqlQuery.executeUpdate(); return null; } }); }
From source file:com.abiquo.server.core.infrastructure.RackDAO.java
License:Open Source License
/** * Obtains the racks (prefiltered by target datacenter and virtualdatacenter) with minimal VLANS * // and with vms deployed/* w ww . java 2 s . co m*/ */ public List<Integer> getRackIdByMinVLANCount(final int idDatacenter) { SQLQuery query = getSession().createSQLQuery(SQL_RACK_IDS_BY_MIN_VLAN_COUNT); query.setInteger("idDatacenter", idDatacenter); return query.list(); }
From source file:com.aw.core.db.support.WhereBuilder2.java
License:Open Source License
public void setParams(SQLQuery sqlQuery) { for (int i = 0; i < params.size(); i++) { Object param = params.get(i); if (param instanceof Long) sqlQuery.setLong(i, (Long) param); else if (param instanceof Integer) sqlQuery.setInteger(i, (Integer) param); else if (param instanceof Date) sqlQuery.setDate(i, (Date) param); else if (param instanceof String) sqlQuery.setString(i, (String) param); else if (param instanceof BigDecimal) sqlQuery.setBigDecimal(i, (BigDecimal) param); else if (param == null) sqlQuery.setParameter(i, null); else/*ww w . java2 s . c o m*/ throw new IllegalArgumentException("Implementar codigo param:" + param.getClass()); } //To change body of created methods use File | Settings | File Templates. }
From source file:com.bitranger.parknshop.buyer.dao.CustomerFavouriteItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CustomerFavouriteItem> findByCustomerId(final Integer psCustomerId, final FetchOption option) { try {/*from w ww. j av a 2 s. c om*/ return getHibernateTemplate().executeFind(new HibernateCallback<List<CustomerFavouriteItem>>() { @Override public List<CustomerFavouriteItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session .createSQLQuery("select * from customer_favourite_item as C where C.id_customer = ?" + " order by C.time_created " + (option.sortOption == SortOption.ASCENDING ? "asc" : "desc") + " limit ? offset ?"); query.setInteger(0, psCustomerId); query.setInteger(1, option.limit); query.setInteger(2, option.offset); query.addEntity(CustomerFavouriteItem.class); return query.list(); } }); } catch (RuntimeException e) { log.error("get failed", e); throw e; } }
From source file:com.bitranger.parknshop.buyer.dao.impl.CartCustomerItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . j a v a2s .c o m public List<CartCustomerItem> findByCustomerId(final Integer psCustomerId, final FetchOption option) { log.debug("getting CartCustomerItem instance with psCustomerId: " + psCustomerId); try { return getHibernateTemplate().executeFind(new HibernateCallback<List<CartCustomerItem>>() { @Override public List<CartCustomerItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session .createSQLQuery("select * from cart_customer_item as C where C.id_customer = ?" + " order by C.time_created " + (option.sortOption == SortOption.ASCENDING ? "asc" : "desc") + " limit ? offset ?"); query.setInteger(0, psCustomerId); query.setInteger(1, option.limit); query.setInteger(2, option.offset); query.addEntity(CartCustomerItem.class); return query.list(); } }); } catch (RuntimeException e) { log.error("get failed", e); throw e; } }
From source file:com.bitranger.parknshop.buyer.dao.PsNoticeCustomerDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<PsNoticeCustomer> getLatest(final int customerID, final int n) { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsNoticeCustomer>>() { @Override//from w w w .ja va2 s .com public List<PsNoticeCustomer> doInHibernate(Session arg0) throws HibernateException, SQLException { SQLQuery q = arg0.createSQLQuery(" select ps_notice_customer as NC " + " where NC.is_valid = 1 and id_customer = ? " + " order by time_created desc limit ?"); q.setInteger(0, customerID); q.setInteger(1, n); q.addEntity(PsNoticeCustomer.class); return q.list(); } }); }
From source file:com.bitranger.parknshop.common.ads.PsPromotItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<PsPromotItem> findBySeller(final int id) { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsPromotItem>>() { @Override/*ww w. j a v a 2s. c o m*/ public List<PsPromotItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery q = session.createSQLQuery(" select IP.* from ps_promot_item as IP " + " inner join ps_item as IT on IT.id = IP.id_item " + " inner join ps_shop as SP on SP.id = IT.id_shop " + " where SP.id_seller = ? "); q.setInteger(0, id); q.addEntity(PsPromotItem.class); return q.list(); } }); }
From source file:com.bitranger.parknshop.common.dao.impl.PsCommentDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from ww w . j av a 2 s .c o m*/ public List<PsComment> findByCustomerId(final Integer customerId, final FetchOption option) { log.debug("findByCustomerId: " + customerId); try { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsComment>>() { @Override public List<PsComment> doInHibernate(Session arg0) throws HibernateException, SQLException { SQLQuery query = arg0.createSQLQuery("select * from ps_comment where id_customer = ? " + "order by time_created " + (option.sortOption == SortOption.ASCENDING ? " asc " : " desc ") + "limit ?, ?"); query.setInteger(0, customerId); query.setInteger(1, option.offset); query.setInteger(2, option.limit); query.addEntity(PsComment.class); return query.list(); } }); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } }
From source file:com.bitranger.parknshop.common.dao.impl.PsCommentDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from ww w . jav a2 s .c o m public List<PsComment> findByItemId(final Integer itemId, final FetchOption option) { log.debug("findByItemId: " + itemId); try { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsComment>>() { @Override public List<PsComment> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery("select * from ps_comment where id_item = ? " + " order by time_created " + (option.sortOption == SortOption.ASCENDING ? " asc " : " desc ") + "limit ?, ?"); query.setInteger(0, itemId); query.setInteger(1, option.offset); query.setInteger(2, option.limit); query.addEntity(PsComment.class); return query.list(); } }); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } }
From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java
License:Open Source License
/** select IT.*, count(IT.count_purchase) as CT from ps_item as IT where IT.id_category = ?//from w w w .ja v a 2 s . c o m order by IT.time_created desc limit 0, ? */ @SuppressWarnings("unchecked") @Override public List<PsItem> selectLatest(final int categoryID, final int limit) { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() { @Override public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session .createSQLQuery(" select IT.*, count(IT.count_purchase) as CT from ps_item as IT " + " where IT.id_category = ? " + " order by IT.time_created desc " + " limit 0, ? "); query.addEntity(PsItem.class); query.setInteger(0, categoryID); query.setInteger(1, limit); return query.list(); } }); }