List of usage examples for org.hibernate SQLQuery setParameter
@Override NativeQuery<T> setParameter(int position, Object val);
From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java
public void saveHotCode(Long fileId, String code, Integer user) throws Exception { StringBuilder sb = new StringBuilder(); sb.append(//w ww.j a va 2s . com "insert into lcl_booking_hot_code(file_number_id,code,entered_datetime,entered_by_user_id,modified_datetime,modified_by_user_id) "); sb.append(" values(:fileId,:code,:now,:user,:now,:user)"); SQLQuery query = getCurrentSession().createSQLQuery(sb.toString()); query.setParameter("fileId", fileId); query.setParameter("code", code); query.setParameter("now", new Date()); query.setParameter("user", user); query.executeUpdate(); }
From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java
public Boolean isHazmatHotCodeExist(String fileId) throws Exception { StringBuilder queryStr = new StringBuilder(); queryStr.append("SELECT if((SELECT hazrds FROM ").append(dataBaseName).append( ".ldgins WHERE loadcd = SUBSTRING_INDEX(lp.code,'/',1))='y',true,false) as result FROM lcl_booking_hot_code lp JOIN genericcode_dup gd "); queryStr.append("ON gd.code = SUBSTRING_INDEX(lp.code,'/',1) and "); queryStr.append("gd.Codetypeid= (SELECT codetypeid FROM codetype WHERE description='Hot Codes') "); queryStr.append("AND gd.Field1='Y' WHERE lp.file_number_id =:fileId limit 1"); SQLQuery query = getCurrentSession().createSQLQuery(queryStr.toString()); query.setParameter("fileId", fileId); query.addScalar("result", BooleanType.INSTANCE); return (Boolean) (query.uniqueResult() != null ? query.uniqueResult() : Boolean.FALSE); }
From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java
public boolean qtHazmatCodeExit(String fileId) throws Exception { StringBuilder sb = new StringBuilder(); sb.append("SELECT "); sb.append(" IF("); sb.append(" (SELECT "); sb.append(" hazrds "); sb.append(" FROM "); sb.append(dataBaseName).append(".ldgins"); sb.append(" WHERE loadcd = SUBSTRING_INDEX(lq.code, '/', 1)) = 'y',"); sb.append(" TRUE,"); sb.append(" FALSE"); sb.append(" ) AS hazStatus "); sb.append(" FROM"); sb.append(" lcl_quote_hot_code lq "); sb.append(" JOIN genericcode_dup gd "); sb.append(" ON gd.code = SUBSTRING_INDEX(lq.code, '/', 1) "); sb.append(" AND gd.Codetypeid = "); sb.append(" (SELECT "); sb.append(" codetypeid "); sb.append(" FROM"); sb.append(" codetype "); sb.append(" WHERE description = 'Hot Codes') "); sb.append(" AND gd.Field1 = 'Y' "); sb.append(" WHERE lq.file_number_id = :fileId"); SQLQuery queryObject = getCurrentSession().createSQLQuery(sb.toString()); queryObject.setParameter("fileId", fileId); queryObject.addScalar("hazStatus", BooleanType.INSTANCE); return (Boolean) (queryObject.uniqueResult() != null ? queryObject.uniqueResult() : Boolean.FALSE); }
From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java
public boolean isHotCodeExistsForConsolidateFile(String fileId, String hotCode) throws Exception { StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append(" SELECT IF(COUNT(*)>0,'true','false') as result FROM lcl_booking_hot_code hc "); queryBuilder.append(" JOIN lcl_file_number fn ON fn.id=hc.file_number_id WHERE "); queryBuilder.append(/* www.j a v a 2 s.c o m*/ " fn.id IN (SELECT lcl_file_number_id_a FROM `lcl_consolidation` WHERE lcl_file_number_id_b = "); queryBuilder.append( " (SELECT lcl_file_number_id_b FROM `lcl_consolidation` WHERE lcl_file_number_id_a =:fileId)) "); queryBuilder.append(" AND hc.`code` =:hotCode "); SQLQuery query = getCurrentSession().createSQLQuery(queryBuilder.toString()); query.setParameter("fileId", fileId); query.setParameter("hotCode", hotCode); return (boolean) query.addScalar("result", BooleanType.INSTANCE).uniqueResult(); }
From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingSegregationDao.java
public Boolean isCheckedSegregationDr(Long fileId) throws Exception { StringBuilder queryStr = new StringBuilder(); queryStr.append("SELECT IF(COUNT(*)>0,true,false) as result FROM lcl_booking_segregation"); queryStr.append(" WHERE child_file_number_id=:fileId"); SQLQuery query = getCurrentSession().createSQLQuery(queryStr.toString()); query.setParameter("fileId", fileId); query.addScalar("result", BooleanType.INSTANCE); return (Boolean) query.setMaxResults(1).uniqueResult(); }
From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclQuoteHotCodeDAO.java
public boolean isHotCodeExist(String Code, String fileId) throws Exception { SQLQuery query = getCurrentSession() .createSQLQuery("select if(count(*)<1,true,false) as result from lcl_quote_hot_code " + " where code=:code and file_number_id=:fileId"); query.setParameter("fileId", fileId); query.setParameter("code", Code); query.addScalar("result", BooleanType.INSTANCE); return (Boolean) query.uniqueResult(); }
From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclQuoteHotCodeDAO.java
public void insertQuery(String fileId, String code, Integer user) throws Exception { StringBuilder sb = new StringBuilder(); sb.append(// ww w.j a v a 2 s .c o m "insert into lcl_quote_hot_code(file_number_id,code,entered_datetime,entered_by_user_id,modified_datetime,modified_by_user_id) "); sb.append(" values(:fileId,:code,:now,:user,:now,:user)"); SQLQuery query = getCurrentSession().createSQLQuery(sb.toString()); query.setParameter("fileId", fileId); query.setParameter("code", code); query.setParameter("now", new Date()); query.setParameter("user", user); query.executeUpdate(); }
From source file:com.heimaide.server.common.persistence.BaseDao.java
License:Open Source License
/** * 2015720 ??????./* ww w.ja va 2 s . c o m*/ * * @param sqlString * @param param * @return */ public SQLQuery createSqlQuery(String sqlString, List param) { SQLQuery query = getSession().createSQLQuery(sqlString); if (param != null && param.size() > 0) { for (int i = 0; i < param.size(); i++) { query.setParameter(i, param.get(i)); } } return query; }
From source file:com.hibernate.dao.CarinfoDAO.java
public CarInfoJSON selectcarinfo(String phonenum) { // session/*from w w w .j a va 2 s . co m*/ Session session = HibernateSessionFactory.getSession(); CarInfoJSON carinfo = new CarInfoJSON(); Transaction tx = session.beginTransaction(); tx.begin(); SQLQuery query = session.createSQLQuery("SELECT * FROM car_info where DriverID=:phonenum"); query.setParameter("phonenum", phonenum); try { Object[] result = (Object[]) query.list().get(0); tx.commit(); carinfo.setId(result[0].toString()); carinfo.setCarNum(result[1].toString()); carinfo.setDriverId(result[2].toString()); carinfo.setCarBrand(result[3].toString()); carinfo.setCarModel(result[4].toString()); carinfo.setCarColor(result[5].toString()); carinfo.setCarCapacity(result[6].toString()); // carinfo.setDrivedYears(result[7].toString()); // carinfo.setCarPohto(result[8].toString()); // carinfo.setDriveLicense(result[9].toString()); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); // } finally { // session session.close(); } return carinfo; }
From source file:com.hrms.manager.DependentsInfoManager.java
public int delete(int id) { Session s = HibernateUtil.getSessionFactory().openSession(); Transaction t = s.beginTransaction(); // System.out.println(quarterId); try {/*ww w.j a va 2 s. c om*/ //QuarterAllotment q=(QuarterAllotment)s.get(QuarterAllotment.class,quarterId); // ResidentialQuarters q=(ResidentialQuarters)s.get(ResidentialQuarters.class, quarterId); String sql = "delete from dependents_information where id=:id"; SQLQuery query = s.createSQLQuery(sql); query.setParameter("id", id); query.executeUpdate(); t.commit(); } catch (Exception e) { System.out.println(e); } return id; }