Ejemplo n.º 1
0
  /**
   * Execute a stored procedure
   *
   * @param statementScope - the request scope
   * @param conn - the database connection
   * @param sql - the sql to call the procedure
   * @param parameters - the parameters for the procedure
   * @param skipResults - the number of results to skip
   * @param maxResults - the maximum number of results to return
   * @param callback - a row handler for processing the results
   * @throws SQLException - if the procedure fails
   */
  public void executeQueryProcedure(
      StatementScope statementScope,
      Connection conn,
      String sql,
      Object[] parameters,
      int skipResults,
      int maxResults,
      RowHandlerCallback callback)
      throws SQLException {
    ErrorContext errorContext = statementScope.getErrorContext();
    errorContext.setActivity("executing query procedure");
    errorContext.setObjectId(sql);
    CallableStatement cs = null;
    ResultSet rs = null;
    setupResultObjectFactory(statementScope);
    try {
      errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
      Integer rsType = statementScope.getStatement().getResultSetType();
      if (rsType != null) {
        cs = prepareCall(statementScope.getSession(), conn, sql, rsType);
      } else {
        cs = prepareCall(statementScope.getSession(), conn, sql);
      }
      setStatementTimeout(statementScope.getStatement(), cs);
      Integer fetchSize = statementScope.getStatement().getFetchSize();
      if (fetchSize != null) {
        cs.setFetchSize(fetchSize.intValue());
      }
      ParameterMap parameterMap = statementScope.getParameterMap();
      ParameterMapping[] mappings = parameterMap.getParameterMappings();
      errorContext.setMoreInfo("Check the output parameters (register output parameters failed).");
      registerOutputParameters(cs, mappings);
      errorContext.setMoreInfo("Check the parameters (set parameters failed).");
      parameterMap.setParameters(statementScope, cs, parameters);
      errorContext.setMoreInfo("Check the statement (update procedure failed).");
      cs.execute();
      errorContext.setMoreInfo("Check the results (failed to retrieve results).");

      // Begin ResultSet Handling
      rs = handleMultipleResults(cs, statementScope, skipResults, maxResults, callback);
      // End ResultSet Handling
      errorContext.setMoreInfo(
          "Check the output parameters (retrieval of output parameters failed).");
      retrieveOutputParameters(statementScope, cs, mappings, parameters, callback);

    } finally {
      try {
        closeResultSet(rs);
      } finally {
        closeStatement(statementScope.getSession(), cs);
      }
    }
  }
  /**
   * Obtiene un conjunto de registros en base ael filtro de búsqueda.
   *
   * @param parametros Parámetros que se le envían a la consulta para obtener el conjunto de
   *     registros deseados.
   * @return Lista de registros.
   * @throws SQLException Si se genera un error al accesar la base de datos.
   */
  public LinkedList getRegistros(Registro parametros) throws SQLException {
    LinkedList lista = new LinkedList();
    Registro registro = new Registro();

    String sImporte = "";
    String sFechaAplicacion = "";
    String sIdPrestamoGrupo = "";
    String sIdCliente = "";
    String sImpDeuda = "";
    float fImpDeuda;
    String sExcedente = "";
    float fExcedente;

    sImporte = (String) parametros.getDefCampo("IMPORTE");
    sExcedente = (String) parametros.getDefCampo("EXCEDENTE");

    System.out.println("sImporte" + sImporte);
    System.out.println("sExcedente" + sExcedente);

    sSql =
        "SELECT \n"
            + "PG.CVE_GPO_EMPRESA, \n"
            + "PG.CVE_EMPRESA, \n"
            + "PG.ID_GRUPO, \n"
            + "G.NOM_GRUPO, \n"
            + "G.ID_COORDINADOR \n"
            + "FROM \n"
            + "SIM_PRESTAMO_GRUPO PG, \n"
            + "SIM_GRUPO G \n"
            + "WHERE PG.CVE_GPO_EMPRESA = '"
            + (String) parametros.getDefCampo("CVE_GPO_EMPRESA")
            + "' \n"
            + "AND PG.CVE_EMPRESA = '"
            + (String) parametros.getDefCampo("CVE_EMPRESA")
            + "' \n"
            + "AND PG.ID_PRESTAMO_GRUPO = '"
            + (String) parametros.getDefCampo("ID_PRESTAMO_GRUPO")
            + "' \n"
            + "AND G.CVE_GPO_EMPRESA = PG.CVE_GPO_EMPRESA \n"
            + "AND G.CVE_EMPRESA = PG.CVE_EMPRESA \n"
            + "AND G.ID_GRUPO = PG.ID_GRUPO \n";
    ejecutaSql();
    if (rs.next()) {
      sIdCliente = rs.getString("ID_COORDINADOR");
    }

    sSql =
        " SELECT TO_CHAR(TO_DATE('"
            + (String) parametros.getDefCampo("FECHA_MOVIMIENTO")
            + "','DD-MM-YYYY'),'DD-MON-YYYY') F_APLICACION FROM DUAL";
    ejecutaSql();

    if (rs.next()) {
      sFechaAplicacion = rs.getString("F_APLICACION");
    }

    sIdPrestamoGrupo = (String) parametros.getDefCampo("ID_PRESTAMO_GRUPO");
    String sCallable = "begin ? := PKG_CREDITO.fCalculaProporcion(?,?,?,?,?,?); end;";
    CallableStatement cstmt = conn.prepareCall(sCallable);
    cstmt.setFetchSize(10000);
    cstmt.registerOutParameter(1, OracleTypes.CURSOR);
    cstmt.registerOutParameter(7, java.sql.Types.VARCHAR); // registra parametro de salida
    cstmt.setString(2, (String) parametros.getDefCampo("CVE_GPO_EMPRESA"));
    cstmt.setString(3, (String) parametros.getDefCampo("CVE_EMPRESA"));
    cstmt.setString(4, sIdPrestamoGrupo);
    cstmt.setString(5, sFechaAplicacion);
    cstmt.setString(6, sImporte);
    cstmt.setString(7, "");
    // EJECUTA EL PROCEDIMIENTO ALMACENADO
    cstmt.executeQuery();
    ResultSet rs = (ResultSet) cstmt.getObject(1);

    while (rs.next()) {
      registro.addDefCampo("ID_PRESTAMO", rs.getString("ID_PRESTAMO"));
      registro.addDefCampo("ID_CLIENTE", rs.getString("ID_CLIENTE"));
      registro.addDefCampo("NOM_COMPLETO", rs.getString("NOM_COMPLETO"));
      registro.addDefCampo("IMP_DEUDA", rs.getString("IMP_DEUDA"));
      // Pregunta si se trata del presidende del grupo
      if (!sExcedente.equals("0")) {
        if (rs.getString("ID_CLIENTE").equals(sIdCliente)) {
          sImpDeuda = rs.getString("IMP_DEUDA");
          System.out.println("sImpDeuda************** del presidente: " + sImpDeuda);
          fImpDeuda = (Float.parseFloat(sImpDeuda));
          fExcedente = (Float.parseFloat(sExcedente));
          fImpDeuda = fImpDeuda + fExcedente;
          sImpDeuda = Float.toString(fImpDeuda);

          System.out.println("JUNTO CON EL EXCEDENTE RESULTA SER: " + fImpDeuda);
          registro.addDefCampo("IMP_DEUDA", sImpDeuda);
        }
      }

      lista.add(registro);
      registro = new Registro();
    }

    rs.close();
    cstmt.close();
    return lista;
  }
Ejemplo n.º 3
0
 /** @see java.sql.Statement#setFetchSize(int) */
 public void setFetchSize(int rows) throws SQLException {
   original.setFetchSize(rows);
 }