@SuppressWarnings("unchecked") public List<Person> loadPersonList(boolean selectable) throws HibernateException { Session session = HibernateSessionFactory.currentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(Person.class); criteria.add(Expression.eq("active", true)); if (selectable) { criteria.add(Expression.eq("selectable", true)); } List<Person> list = criteria.list(); transaction.commit(); HibernateSessionFactory.closeSession(); return list; }
private List getLogEntries(String nhsno, Calendar startdate, Calendar enddate) throws HibernateException { List logEntries = new ArrayList(); if (nhsno != null && !nhsno.equals("")) { Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction(); Criteria criteria = session.createCriteria(LogEntry.class); criteria.add(Expression.between("date", startdate, enddate)); criteria.add(Expression.like("nhsno", "%" + nhsno + "%")); criteria.addOrder(Order.asc("id")); logEntries = criteria.list(); tx.commit(); HibernateUtil.closeSession(); } return logEntries; }
public List<Person> loadExcludedPersonList(List<String> excludeList, boolean selectable) throws HibernateException { Session session = HibernateSessionFactory.currentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(Person.class); criteria.add(Expression.eq("active", true)); if (selectable) { criteria.add(Expression.eq("selectable", true)); } if (excludeList != null && !excludeList.isEmpty()) { criteria.add(Expression.not(Expression.in("id", excludeList))); } List<Person> list = criteria.list(); transaction.commit(); HibernateSessionFactory.closeSession(); return list; }
public TemplateData findTemplateByName(String name) throws HibernateException { Session session = HibernateSessionFactory.currentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(TemplateData.class); criteria.add(Expression.eq("name", name)); criteria.setMaxResults(1); TemplateData result = (TemplateData) criteria.uniqueResult(); transaction.commit(); HibernateSessionFactory.closeSession(); return result; }
public TemplateData loadByResourceKey(String key) throws HibernateException { Session session = HibernateSessionFactory.currentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(TemplateData.class); criteria.add(Expression.eq("resourceKey", key)); criteria.setMaxResults(1); TemplateData result = (TemplateData) criteria.uniqueResult(); transaction.commit(); HibernateSessionFactory.closeSession(); return result; }
public Person findPersonByEmail(String emailAddress) throws HibernateException { Session session = HibernateSessionFactory.currentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(Person.class); // criteria.createAlias("emailAddesses", "email"); criteria.add(Expression.eq("emailAddress", emailAddress)); // criteria.add(Expression.like("realname", personalName, // MatchMode.ANYWHERE)); criteria.setMaxResults(1); Person person = (Person) criteria.uniqueResult(); transaction.commit(); HibernateSessionFactory.closeSession(); return person; }
public Person authenticatePerson(String username, char[] password) throws HibernateException { Session session = HibernateSessionFactory.currentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(Person.class); criteria.add(Expression.eq("username", username)); criteria.setMaxResults(1); Person person = (Person) criteria.uniqueResult(); transaction.commit(); HibernateSessionFactory.closeSession(); logger.debug("Found person: " + person.getUsername()); if (person.checkPlainPassword(new String(password))) { return person; } return null; }
@SuppressWarnings("unchecked") public Person loadPersonForPrincipal(Principal principal) throws HibernateException { // Principal principal = request.getUserPrincipal(); Session session = HibernateSessionFactory.currentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria = session.createCriteria(Person.class); criteria.add(Expression.eq("username", principal.getName())); criteria.setMaxResults(1); List<Person> personList = criteria.list(); Person person = null; if (personList.size() == 1) { person = personList.get(0); } transaction.commit(); HibernateSessionFactory.closeSession(); return person; }
private List getUserDeptList(Integer userId, String entidad, List deptListLDAP) throws SecurityException { String sqlUsrOfic = "id in (select idofic from scr_usrofic where iduser = "******")"); Criteria criteriaResults = session.createCriteria(ScrOfic.class); criteriaResults.add(Expression.sql(query.toString())); List list = criteriaResults.list(); if (deptListLDAP != null) { deptList.addAll(deptListLDAP); } if (list != null && list.size() > 0) { Iterator it = list.iterator(); while (it.hasNext()) { ScrOfic ofic = (ScrOfic) it.next(); if (!deptList.contains(new Integer(ofic.getDeptid()))) deptList.add(new Integer(ofic.getDeptid())); } } return deptList; } catch (Exception e) { log.error("Impossible to load other offices for user [" + userId + "]", e); throw new SecurityException(SecurityException.ERROR_USER_NOTFOUND); } }
public static ValidationResults getCitiesFromProv( String sessionID, int firstRow, int idCrl, int maxResults, String where, String additionalFieldName, String docColName, String entidad) throws AttributesException, SessionException, ValidationException { Validator.validate_String_NotNull_LengthMayorZero( sessionID, ValidationException.ATTRIBUTE_SESSION); Validator.validate_String_NotNull_LengthMayorZero( sessionID, ValidationException.ATTRIBUTE_SESSION); ValidationResults result = new ValidationResults(); Transaction tran = null; try { Session session = HibernateUtil.currentSession(entidad); tran = session.beginTransaction(); // Recuperamos la sesión CacheFactory.getCacheInterface().getCacheEntry(sessionID); // Calculamos el tamaño de los resultados Criteria criteriaResults = session.createCriteria(ScrCity.class); StringBuffer querySize = new StringBuffer(); querySize.append("select count(*) from "); querySize.append(HIBERNATE_ScrCity); if (where != null && where.length() > 0) { querySize.append(" as scr where "); } else { querySize.append(" as scr where scr.idProv = "); querySize.append(idCrl); criteriaResults.add(Expression.eq("idProv", new Integer(idCrl))); } result = getValidationResults( session, criteriaResults, querySize.toString(), where, 1, firstRow, maxResults, "name"); result.setAdditionalFieldName(additionalFieldName); result.setDocColName(docColName); // result.setResults(cities); HibernateUtil.commitTransaction(tran); return result; } catch (Exception e) { log.error( "Impossible to load cities for getProvForCities for session [" + sessionID + "]", e); throw new AttributesException(AttributesException.ERROR_CANNOT_FIND_PROV); } finally { HibernateUtil.closeSession(entidad); } }