List of usage examples for org.hibernate SQLQuery uniqueResult
R uniqueResult();
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)); }//from ww w .j a v a2 s.com } String result = q.uniqueResult().toString(); BigInteger count = new BigInteger(result); return count; }
From source file:com.poka.dao.impl.BaseDao.java
public String getFunc(String sql, Map<String, Object> params) { String result = null;/*from ww w . j av a2 s. c o m*/ Transaction transaction = null; transaction = getCurrentSession().beginTransaction(); SQLQuery q = getCurrentSession().createSQLQuery(sql); if (params != null && !params.isEmpty()) { for (String key : params.keySet()) { q.setParameter(key, params.get(key)); } } result = (String) q.uniqueResult(); transaction.commit(); return result; }
From source file:com.ps.dao.UsuarioDao.java
@Override public Map loginControl(String user, String pass) { sql = "SELECT * FROM PSV_ROLES WHERE usuario='" + user + "' AND clave='" + pass + "'"; session = HibernateUtil.getSessionFactory().getCurrentSession(); try {/* www . j a va 2s. com*/ trans = session.beginTransaction(); SQLQuery result = session.createSQLQuery(sql); result.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); Object data = result.uniqueResult(); Map row = (Map) data; trans.commit(); return row; } catch (Exception e) { System.out.println(e); trans.rollback(); return null; } }
From source file:com.sangupta.jerry.hibernate.HibernateUtils.java
License:Apache License
/** * Method to fetch the next value in the given sequence name. * // ww w . j a v a2 s . com * @param hibernateTemplate the {@link HibernateTemplate} to access Hibernate with * * @param sequenceName the name of the sequence * * @return the Long value as returned by the sequence, <code>null</code> if no value is obtained * from the database. * */ @Transactional public static Long getNextSequenceValue(HibernateTemplate hibernateTemplate, final String sequenceName) { // TODO: following query may be susceptible to SQL injection final String query = "select " + sequenceName + ".nextval as VALUE from DUAL"; Long result = hibernateTemplate.executeWithNewSession(new HibernateCallback<Long>() { public Long doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery q = session.createSQLQuery(query); Object object = q.uniqueResult(); if (object instanceof BigDecimal) { return ((BigDecimal) object).longValue(); } if (object instanceof Long) { return (Long) object; } return null; } }); return result; }
From source file:com.school.dao.UserImplement.java
@Override public Stuff getUser(String userEmail, String userPassword) { Stuff user = null;// www.j a va 2 s . c o m try { hibernateDriver.openSession(); String getUserSql = "Select u.REC_ID , u.USER_TYPE ,u.JOIN_DATE,u.FAMILY_INFO_ID,u.PERSONAL_INFO_ID,u.CLASS_ID,u.STAGE_ID from USERS u INNER JOIN PERSONAL_INFO p ON p.EMAIL= :userEmail and p.PASSWORD= :userPassword"; SQLQuery query = hibernateDriver.getSession().createSQLQuery(getUserSql); query.addEntity(Stuff.class); query.setResultTransformer(Criteria.PROJECTION); query.setParameter("userEmail", userEmail); query.setParameter("userPassword", userPassword); user = (Stuff) query.uniqueResult(); hibernateDriver.closeSession(); } catch (Exception ex) { ex.printStackTrace(); } return user; }
From source file:com.scopix.periscope.queuemanagement.dao.QueueManagementHibernateDAO.java
License:Open Source License
/** * Cambia la prioridad de un pending evaluation en una cola determinada * * @param startPosition inicio de posicion * @param queueNameId id de cola asociada *//* ww w . ja v a2 s . c o m*/ public void changePriorityToPendingEvaluation(int startPosition, Integer queueNameId) { String hql = "SELECT 1 FROM changePriorityToPendingEvaluation(" + startPosition + ", " + queueNameId + ")"; SQLQuery query = this.getSession().createSQLQuery(hql); query.uniqueResult(); }
From source file:com.se.common.CommonFunctions.java
public static long getComId(String pn, int manId) throws PartNumberException { try {//from ww w . j a v a 2 s .co m SQLQuery aa = session.createSQLQuery("SELECT COM_ID FROM CM.XLP_SE_COMPONENT " + " WHERE MAN_ID = " + manId + " AND COM_PARTNUM = '" + pn + "'"); long comId = Long.parseLong(aa.uniqueResult().toString()); return comId; } catch (Exception ex) { throw new PartNumberException(); } }
From source file:com.se.common.CommonFunctions.java
public static int getPlId(String plName) throws PlException { if (plName == null) { throw new PlException(); } else {/*from w ww .ja v a 2 s. com*/ try { SQLQuery aa = session.createSQLQuery( "select pl_Id from cm.xlp_se_pl where lower(pl_name) = lower('" + plName + "')"); int plId = Integer.parseInt(aa.uniqueResult().toString()); return plId; } catch (Exception ex) { throw new PlException(); } } }
From source file:com.se.common.CommonFunctions.java
public static int getVendorId(String vendorName) throws VendorException { if (vendorName == null || vendorName.equals("")) { return 0; } else {//from ww w . j av a 2 s.c o m try { SQLQuery aa = session.createSQLQuery( "select man_id from CM.XLP_SE_MANUFACTURER where MAN_NAME = '" + vendorName + "'"); int vendorId = Integer.parseInt(aa.uniqueResult().toString()); return vendorId; } catch (Exception ex) { throw new VendorException(); } } }
From source file:com.se.common.CommonFunctions.java
public static Object[] getParaFeatureId(String fetName, int plId) throws FeatureNameException { if (fetName == null) { throw new FeatureNameException("Not Valid SE Feature"); } else {/*from w ww.j a va2s .c o m*/ try { // SELECT * FROM CM.XLP_SE_FEATURE WHERE FET_NAME = 'Logic Family' AND pl_id = 2314 SQLQuery aa = session .createSQLQuery("SELECT FET_ID, COL_NM FROM CM.XLP_SE_FEATURE WHERE FET_NAME = '" + fetName + "' AND pl_id = " + plId); Object[] c = (Object[]) aa.uniqueResult(); // long fetId = Integer.parseInt(c[0].toString()); // String colnm = c[1].toString(); return c; } catch (Exception ex) { ex.printStackTrace(); throw new FeatureNameException("Not Valid SE Feature"); // try{ // int fetId = getPkgFeatureId(fetName); // return fetId; // }catch(Exception e){ // throw new FeatureNameException("Error While validating Feature Name"); // } } } }