List of usage examples for org.hibernate Query setLong
@Deprecated @SuppressWarnings("unchecked") default Query<R> setLong(String name, long val)
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public void reAuthenticate(Long userId) { try {/*from w w w .j a v a 2 s.co m*/ Query query = sessionFactory.getCurrentSession() .createQuery("update User set avatarAuthenticate=0, updateTime=? where userId=?"); query.setLong(0, System.currentTimeMillis()); query.setLong(1, userId); if (query.executeUpdate() > 0) { JUserCache.getInstance().removeUser(userId); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public void changeTelephone(Long userId, Long telephone) { try {/* w w w.j ava2 s.c o m*/ Query query = sessionFactory.getCurrentSession() .createQuery("update User obj set obj.telephone=? where obj.userId=?"); query.setLong(0, telephone); query.setLong(1, userId); if (query.executeUpdate() > 0) { JUserCache.getInstance().removeUser(userId); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public int isTelephoneExist(Long telephone) { try {// w w w .jav a 2 s. c om Query query = sessionFactory.getCurrentSession().createQuery("from User user where user.telephone=?"); query.setLong(0, telephone); List<Object> list = query.list(); if (list == null || list.isEmpty()) { return 0; } return list.size(); } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public void setIdNumberAuthenticated(Long userId, Long certificateId, int auth) { try {/* w w w . j ava 2 s. c om*/ String hql = "update User user set user.isAuthenticate=?, user.updateTime=?, user.certificateId=? where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, auth); query.setLong(1, System.currentTimeMillis()); query.setLong(2, certificateId); query.setLong(3, userId); if (query.executeUpdate() > 0) { JUserCache.getInstance().removeUser(userId); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public void updateLastLogin(long userId) { try {/*from w w w. j a va2s. com*/ String hql = "update User user set user.lastLogin=?, user.updateTime=? where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, System.currentTimeMillis()); query.setLong(1, System.currentTimeMillis()); query.setLong(2, userId); if (query.executeUpdate() > 0) { // JUserCache.getInstance().removeUser(userId); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getWhiteTable(Long updateTime) { Query query = sessionFactory.getCurrentSession().createQuery("from WhiteList l where l.updateTime>?"); query.setLong(0, updateTime); return query.list(); }
From source file:com.copyright.common.hibernate.SimpleHibernateDao.java
License:Apache License
/** * ?HQL?Query.//from w ww .j a v a 2s .com * * ?find()T,?T. * * @param values ????,?. */ public Query createQuery(final String queryString, final Object... values) { Assert.hasText(queryString, "queryString?"); Query query = getSession().createQuery(queryString); if (values != null && values.length > 0) { if (values[0] instanceof Hashtable) { Hashtable temp = (Hashtable) values[0]; query = setParamHash(query, temp); } else { if (values[0] instanceof List) { List temp = (List) values[0]; int size = temp.size(); for (int i = 0; i < size; i++) { Object param = temp.get(i); //query.setParameter(i,values[i]); if (param instanceof String) { String paramValue = (String) param; query.setString(i, paramValue); } else { if (param instanceof Integer) { Integer paramValue = (Integer) param; query.setInteger(i, paramValue.intValue()); } else { if (param instanceof Long) { Long paramValue = (Long) param; query.setLong(i, paramValue.longValue()); } else { if (param instanceof Double) { Double paramValue = (Double) param; query.setDouble(i, paramValue.doubleValue()); } else { if (param instanceof Float) { Float paramValue = (Float) param; query.setFloat(i, paramValue.floatValue()); } } } } } } } else { for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); } } } } return query; }
From source file:com.dao.ProgramDAO.java
@SuppressWarnings("unchecked") public List<Program> getProgramsForPatient(long patientId) { Query query = getCurrentSession().createSQLQuery("SELECT * FROM Program WHERE patient_id = ?") .addEntity(Program.class); query.setLong(0, patientId); List<Program> ex = query.list(); return ex;/* w ww .ja va 2s .co m*/ }
From source file:com.dao.ProgramDAO.java
public List<Exercise> getExercisesForPatienId(long patientId) { Query query = getCurrentSession().createSQLQuery( "SELECT * FROM Program INNER JOIN Exercise ON Exercise.exerciseId = exercise_exerciseId WHERE patient_id = ?") .addEntity(Exercise.class); query.setLong(0, patientId); List<Exercise> ex = query.list(); /*List<Integer> exerciseIds = query.setInteger(0, patientId).list(); // w w w . j a v a2 s. c om List<Exercise> exercises = new ArrayList(); for (int i : exerciseIds) { exercises.add(exerciseService.getExercise(i)); }*/ return ex; }
From source file:com.db4o.drs.hibernate.impl.Util.java
License:Open Source License
public static ObjectReference getByUUID(Session session, Uuid uuid) { String alias = "objRef"; String uuidPath = alias + "." + ObjectReference.Fields.UUID + "."; String queryString = "from " + "ObjectReference" + " as " + alias + " where " + uuidPath + Uuid.Fields.CREATED + "=?" + " AND " + uuidPath + Uuid.Fields.PROVIDER + "." + ProviderSignature.Fields.SIG + "=?"; Query c = session.createQuery(queryString); c.setLong(0, uuid.getCreated()); c.setBinary(1, uuid.getProvider().getSignature()); final List exisitings = c.list(); int count = exisitings.size(); if (count == 0) return null; else if (count > 1) throw new RuntimeException("Only one ObjectReference should exist"); else {// w w w .j a v a2s . co m return (ObjectReference) exisitings.get(0); } }