예제 #1
0
 @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;
 }
예제 #2
0
 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;
 }
예제 #5
0
 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;
 }
예제 #6
0
 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;
 }
예제 #7
0
 @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;
 }
예제 #8
0
  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);
    }
  }