List of usage examples for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException
public static DataAccessException convertHibernateAccessException(HibernateException ex)
From source file:org.unitedinternet.cosmo.dao.hibernate.ServerPropertyDaoImpl.java
public void setServerProperty(String property, String value) { try {//ww w. j ava 2 s.c om ServerProperty prop = (ServerProperty) getSession() .createQuery("from HibServerProperty where name=:name").setParameter("name", property) .uniqueResult(); if (prop != null) { prop.setValue(value); getSession().update(prop); } else { prop = new HibServerProperty(property, value); getSession().save(prop); } getSession().flush(); } catch (HibernateException e) { throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public User createUser(User user) { try {/*from ww w.jav a 2s . c om*/ if (user == null) { throw new IllegalArgumentException("user is required"); } if (getBaseModelObject(user).getId() != -1) { throw new IllegalArgumentException("new user is required"); } if (findUserByUsernameIgnoreCase(user.getUsername()) != null) { throw new DuplicateUsernameException(user.getUsername()); } if (findUserByEmailIgnoreCase(user.getEmail()) != null) { throw new DuplicateEmailException(user.getEmail()); } if (user.getUid() == null || "".equals(user.getUid())) { user.setUid(getIdGenerator().nextStringIdentifier()); } getSession().save(user); getSession().flush(); return user; } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } catch (ConstraintViolationException cve) { logConstraintViolationException(cve); throw cve; } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public User getUser(String username) { try {//from ww w.jav a 2 s .co m return findUserByUsername(username); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public User getUserByUid(String uid) { if (uid == null) { throw new IllegalArgumentException("uid required"); }/*from w ww. j a va 2 s .c o m*/ try { return findUserByUid(uid); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public User getUserByActivationId(String id) { if (id == null) { throw new IllegalArgumentException("id required"); }//from w ww . ja va2s .co m try { return findUserByActivationId(id); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public User getUserByEmail(String email) { if (email == null) { throw new IllegalArgumentException("email required"); }//from www . j a v a 2 s . c o m try { return findUserByEmail(email); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public Set<User> getUsers() { try {// www . j a v a 2 s. c o m HashSet<User> users = new HashSet<User>(); Iterator it = getSession().getNamedQuery("user.all").iterate(); while (it.hasNext()) { users.add((User) it.next()); } return users; } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public PagedList getUsers(PageCriteria<User.SortType> pageCriteria) { try {//from w w w . j av a 2s . c om Criteria crit = QUERY_CRITERIA_BUILDER.buildQueryCriteria(getSession(), pageCriteria); List<User> results = crit.list(); // Need the total Long size = (Long) getSession().getNamedQuery("user.count").uniqueResult(); return new ArrayPagedList<User, User.SortType>(pageCriteria, results, size.intValue()); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public Set<User> findUsersByPreference(String key, String value) { try {//from w w w .j a va2s. c o m Query hibQuery = getSession().getNamedQuery("users.byPreference"); hibQuery.setParameter("key", key).setParameter("value", value); List<User> results = hibQuery.list(); Set<User> users = new HashSet<User>(); // TODO figure out how to load all properties using HQL for (User user : results) { Hibernate.initialize(user); users.add(user); } return users; } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.UserDaoImpl.java
public void removeUser(String username) { try {/*from w ww . j ava2s. c o m*/ User user = findUserByUsername(username); // delete user if (user != null) { removeUser(user); } } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }