List of usage examples for org.hibernate SQLQuery setParameter
@Override NativeQuery<T> setParameter(int position, Object val);
From source file:com.iluwatar.cqrs.queries.QueryServiceImpl.java
License:Open Source License
@Override public BigInteger getAuthorBooksCount(String username) { BigInteger bookcount = null;//from ww w.j a v a2s . c o m try (Session session = sessionFactory.openSession()) { SQLQuery sqlQuery = session.createSQLQuery("SELECT count(b.title)" + " FROM Book b, Author a where b.author_id = a.id and a.username=:username"); sqlQuery.setParameter("username", username); bookcount = (BigInteger) sqlQuery.uniqueResult(); } return bookcount; }
From source file:com.iwancool.dsm.dao.impl.AbstractBaseGenericORMDaoImpl.java
License:Open Source License
@Override public List<Object[]> findBySql(String sql, Map<String, Object> params) { SQLQuery q = this.getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }// ww w. ja v a 2s. c o m } return q.list(); }
From source file:com.iwancool.dsm.dao.impl.AbstractBaseGenericORMDaoImpl.java
License:Open Source License
@Override public List<Object[]> findBySql(String sql, Map<String, Object> params, int page, int rows) { SQLQuery q = this.getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }/* w ww .j ava 2 s. c om*/ } return q.setFirstResult((page - 1) * rows).setMaxResults(rows).list(); }
From source file:com.iwancool.dsm.dao.impl.AbstractBaseGenericORMDaoImpl.java
License:Open Source License
@Override public int executeSql(String sql, Map<String, Object> params) { SQLQuery q = this.getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }//ww w .j a v a 2 s . co m } return q.executeUpdate(); }
From source file:com.iwancool.dsm.dao.impl.AbstractBaseGenericORMDaoImpl.java
License:Open Source License
@Override public BigInteger countBySql(String sql, Map<String, Object> params) { SQLQuery q = this.getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }/* www. java 2 s .co m*/ } return (BigInteger) q.uniqueResult(); }
From source file:com.iwancool.dsm.dao.impl.AbstractBaseGenericORMDaoImpl.java
License:Open Source License
@Override public Object getObject(String sql, Map<String, Object> params) { SQLQuery q = this.getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }//from w w w. j ava2 s . c o m } return q.uniqueResult(); }
From source file:com.jfootball.dao.hibernate.PlayerDaoImpl.java
License:Open Source License
/** * /*from ww w . j a va 2 s . co m*/ * chiamata alla funzione mysql 'getRank(?,?)' * * * */ public String getRank(Long teamId, Long playerId) { logger.info("Get Rank team" + teamId + " playerId " + playerId); Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); SQLQuery query = session.createSQLQuery("select getRank(?, ?)"); query.setParameter(0, teamId); query.setParameter(1, playerId); String rank = query.uniqueResult().toString(); logger.info("Rank returned"); return rank; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public ArrayList getFieldData(Session session, String module, String moduleRecId) { ArrayList returnList = new ArrayList(); String query1 = "show tables "; SQLQuery sql1 = session.createSQLQuery(query1); ArrayList l = new ArrayList(); l = (ArrayList) sql1.list();/*from w w w.j a v a 2 s . com*/ if (!l.contains(module + "cstm")) { query1 = "CREATE TABLE `" + module + "cstm`(`modulerecid` varchar(36) NOT NULL,`fieldparamid` int(11) NOT NULL, `fieldvalue` varchar(255) NOT NULL, `fieldname` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; sql1 = session.createSQLQuery(query1); sql1.executeUpdate(); } // String query = "SELECT `fieldname`,`fieldvalue`,`fieldtype` FROM " + module + "cstm where modulerecid = ?"; String query = "SELECT cm.fieldname,cm.fieldvalue,cm.fieldparamid, fp.fieldtype FROM " + module + "cstm as cm inner join fieldparams as fp on cm.fieldparamid = fp.id where modulerecid = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, moduleRecId); returnList = (ArrayList) sql.list(); return returnList; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public ArrayList getOnlyFieldName(Session session, HttpServletRequest request, String moduleId) throws SessionExpiredException, ServiceException { ArrayList returnList = new ArrayList(); try {/*ww w. ja va 2s . co m*/ String companyid = AuthHandler.getCompanyid(request); String query = "SELECT distinct `fieldname` FROM fieldparams where moduleid=? and companyid = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, moduleId); sql.setParameter(1, companyid); returnList = (ArrayList) sql.list(); } catch (Exception e) { throw ServiceException.FAILURE("fieldManager.getOnlyFieldName", e); } return returnList; }
From source file:com.krawler.customFieldMaster.fieldManager.java
License:Open Source License
public String customComboValue(Session session, String df) { String status = ""; if (df != null) { ArrayList returnList = new ArrayList(); String query = "SELECT `name` FROM fieldComboData where id = ?"; SQLQuery sql = session.createSQLQuery(query); sql.setParameter(0, df); returnList = (ArrayList) sql.list(); Object[] item1 = returnList.toArray(); status = item1[0].toString();//from w w w . j a v a 2 s.c o m } return status; }