List of usage examples for org.hibernate Session getNamedQuery
org.hibernate.Query getNamedQuery(String queryName);
From source file:com.appeligo.search.entity.ToNotify.java
License:Apache License
/** * //from www.j a va2 s . c om * @param email * @return */ public static ToNotify findByEmail(String email) { Session session = getSession(); Query query = session.getNamedQuery("ToNotify.findByEmail"); query.setString("email", email); return (ToNotify) query.uniqueResult(); }
From source file:com.appeligo.search.entity.User.java
License:Apache License
/** * //from w w w . j av a 2 s . c o m * @param username * @return */ @SuppressWarnings("unchecked") public static User findByUsername(String username) { Session session = getSession(); Query query = session.getNamedQuery("User.findByUsername"); query.setString("username", username); List<User> users = query.list(); if (users.size() > 0) { return users.get(0); } else { return null; } }
From source file:com.appeligo.search.entity.User.java
License:Apache License
private static User findByQuery(String queryName, String paramName, String param) { Session session = getSession(); Query query = session.getNamedQuery(queryName); query.setString(paramName, param);//from w w w.j a va 2 s . c o m List<User> users = query.list(); if (users.size() > 0) { return users.get(0); } else { return null; } }
From source file:com.appeligo.search.entity.User.java
License:Apache License
public boolean isEmailAvailableForUser(String email) { Session session = getSession(); Query query = session.getNamedQuery("User.checkEmailAvailableForUser"); query.setString("email", email); query.setEntity("user", this); List test = query.list();// w ww .j a va2s. co m if (test.size() > 0) { return false; } else { return true; } }
From source file:com.appeligo.search.entity.User.java
License:Apache License
/** * /*from ww w .j a v a2 s. c o m*/ * @param username * @return */ @SuppressWarnings("unchecked") public static User findByUsernameAndSecret(String username, String registrationSecret) { Session session = getSession(); Query query = session.getNamedQuery("User.findByUsernameAndRegistrationSecret"); query.setString("username", username); query.setString("registrationSecret", registrationSecret); if (log.isInfoEnabled()) { log.info("Attempting to load user by " + username + " and " + registrationSecret); } User user = (User) query.uniqueResult(); return user; }
From source file:com.appeligo.search.entity.User.java
License:Apache License
@SuppressWarnings("unchecked") public static List<User> getUsers() { Session session = getSession(); Query query = session.getNamedQuery("User.findAll"); return query.list(); }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
private HibernateCallback createHibernateCallbackWithNamedQuery(final String namedQuery, final int firstResult, final int maxResults, final Object... values) { return new HibernateCallback() { @Override/*w w w .ja v a2 s. c om*/ public Object doInHibernate(Session session) throws HibernateException { final Query query = session.getNamedQuery(namedQuery); return prepareFindByQuery(query, firstResult, maxResults, values); } }; }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@SuppressWarnings("unchecked") public <T> List<T> findByNamedQuery(final String namedQuery, final int firstResult, final int maxResults, final Object... values) { final List<T> list = getHibernateTemplate().executeFind(new HibernateCallback() { @Override/*from w w w . j a v a 2 s.c o m*/ public Object doInHibernate(Session session) throws HibernateException { final Query query = session.getNamedQuery(namedQuery); return prepareFindByQuery(query, firstResult, maxResults, values); } }); traceResults(list); return list; }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@Override public Long countByNamedQuery(final String namedQuery, final Object... values) { return (Long) getHibernateTemplate().execute(new HibernateCallback() { @Override/*from w w w.j av a2 s . c o m*/ public Object doInHibernate(Session session) throws HibernateException { final Query query = session.getNamedQuery(namedQuery); return prepareFindByQuery(query, 0, 0, values).get(0); } }); }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@Override public void deleteByNamedQuery(final String namedQuery, final Object... values) { getHibernateTemplate().execute(new HibernateCallback() { @Override/*from w w w. java2s .c o m*/ public Object doInHibernate(Session session) throws HibernateException { final Query query = session.getNamedQuery(namedQuery); for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); } query.executeUpdate(); return null; } }); }