List of usage examples for org.hibernate SQLQuery setParameter
@Override NativeQuery<T> setParameter(int position, Object val);
From source file:com.necl.core.daoImpl.SectionDaoImpl.java
@Override public Section findById(String division, String section) throws Exception { logger.info("division : " + division + " Section : " + section); String sql = "SELECT DivisionCode, SectionCode, SectionName, SectionBudget, SectionActual " + "FROM tblMaster_Section " + "WHERE (SectionCode = :section) AND (DivisionCode = :division)"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(Section.class); query.setParameter("section", section); query.setParameter("division", division); List results = query.list();/* w w w . j a v a 2s .co m*/ return (Section) results.get(0); }
From source file:com.necl.core.daoImpl.TicketDetailDaoImpl.java
@Override public boolean delete(int id) throws Exception { String sql = "DELETE FROM tblTicketsD WHERE id = :id"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(TicketDetail.class); query.setParameter("id", id); query.executeUpdate();//ww w .j a v a 2 s . co m return true; }
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> storedShowApproves(User user) throws Exception { String sql = "EXEC PRO_ShowApproves :positionCode , :divisionCode , :userName"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("positionCode", user.getPositionCode()); query.setParameter("divisionCode", user.getDivisionCode()); query.setParameter("userName", user.getSsoId()); query.addEntity(TicketHeader.class); List results = query.list();//from ww w . j a v a 2s . c o m return results; }
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> storedShowTicket(String ssoId) throws Exception { String sql = "EXEC PRO_ShowTickets :ssoId"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("ssoId", ssoId); query.addEntity(TicketHeader.class); List results = query.list();/*from w ww . j a v a 2 s. c om*/ return results; }
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> findByType(String type) throws Exception { String sql = "SELECT * FROM tblTicketsH " + "WHERE (TicketType = :ticketType) AND (TicketsFinished = :ticketFinished)" + "ORDER BY ApplicationDate DESC "; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(TicketHeader.class); query.setParameter("ticketType", type); query.setParameter("ticketFinished", "P"); List results = query.list();// www.j a v a 2 s .c o m return results; }
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> findByTypeArea(String type, String area) throws Exception { String sql = "SELECT *\n" + "FROM APP_USER INNER JOIN\n" + "tblMaster_Branch ON APP_USER.branchId = tblMaster_Branch.BranchID INNER JOIN\n" + "tblTicketsH ON APP_USER.SSO_ID = tblTicketsH.ApplicationName\n" + "WHERE (tblTicketsH.TicketType = :ticketType) AND (tblTicketsH.TicketsFinished = :ticketFinished) AND (tblMaster_Branch.Area = :area)\n" + "ORDER BY tblTicketsH.ApplicationDate DESC"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(TicketHeader.class); query.setParameter("ticketType", type); query.setParameter("ticketFinished", "P"); query.setParameter("area", area); List results = query.list();/*from w w w . jav a2 s. c om*/ return results; }
From source file:com.poka.dao.impl.BaseDao.java
@Override public List<T> findBySql(String sql, Map<String, Object> params) { Transaction transaction = null;/*from w w w. jav a 2s . c o m*/ transaction = getCurrentSession().beginTransaction(); SQLQuery q = getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); } } List<T> list = q.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list(); transaction.commit(); return list; }
From source file:com.poka.dao.impl.BaseDao.java
@Override public List<T> findBySql(String sql, Map<String, Object> params, int page, int rows) { SQLQuery q = getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }/*from w ww.j a v a2 s . c o m*/ } return q.setFirstResult((page - 1) * rows).setMaxResults(rows) .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list(); }
From source file:com.poka.dao.impl.BaseDao.java
@Override public int executeSql(String sql, Map<String, Object> params) { Transaction transaction = null;//from ww w .j a va2 s.c o m transaction = getCurrentSession().beginTransaction(); SQLQuery q = getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); } } int result = q.executeUpdate(); transaction.commit(); return result; }
From source file:com.poka.dao.impl.BaseDao.java
@Override public BigInteger countBySql(String sql, Map<String, Object> params) { SQLQuery q = getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); }/*ww w .ja v a2 s. c om*/ } String result = q.uniqueResult().toString(); BigInteger count = new BigInteger(result); return count; }