Beispiel #1
0
  public static ScrCity getScrCityById(String sessionID, int id, String entidad)
      throws AttributesException, SessionException, ValidationException {
    Validator.validate_String_NotNull_LengthMayorZero(
        sessionID, ValidationException.ATTRIBUTE_SESSION);

    ScrCity result = null;
    Transaction tran = null;
    try {
      Session session = HibernateUtil.currentSession(entidad);
      tran = session.beginTransaction();

      // Recuperamos la sesión
      CacheFactory.getCacheInterface().getCacheEntry(sessionID);

      result = (ScrCity) session.load(ScrCity.class, new Integer(id));

      HibernateUtil.commitTransaction(tran);

      return result;
    } catch (SessionException sE) {
      HibernateUtil.rollbackTransaction(tran);
      throw sE;
    } catch (Exception e) {
      HibernateUtil.rollbackTransaction(tran);
      log.error("Impossible to load ScrCity for session [" + sessionID + "]", e);
      throw new AttributesException(AttributesException.ERROR_CANNOT_FIND_CITIES);
    } finally {
      HibernateUtil.closeSession(entidad);
    }
  }
Beispiel #2
0
  public static ValidationResults getProvForCities(
      String sessionID,
      int firstRow,
      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
      StringBuffer querySize = new StringBuffer();
      querySize.append("select count(*) from ");
      querySize.append(HIBERNATE_ScrProv);
      querySize.append(" as scr");
      if (where != null && where.length() > 0) {
        querySize.append(" as scr where ");
      }

      Criteria criteriaResults = session.createCriteria(ScrProv.class);
      result =
          getValidationResults(
              session,
              criteriaResults,
              querySize.toString(),
              where,
              1,
              firstRow,
              maxResults,
              "name");

      result.setAdditionalFieldName(additionalFieldName);
      result.setDocColName(docColName);
      // result.setResults(provincies);

      HibernateUtil.commitTransaction(tran);

      return result;
    } catch (Exception e) {
      log.error(
          "Impossible to load provinces for getProvForCities for session [" + sessionID + "]", e);
      throw new AttributesException(AttributesException.ERROR_CANNOT_FIND_PROV);
    } finally {
      HibernateUtil.closeSession(entidad);
    }
  }