コード例 #1
0
  /* (non-Javadoc)
   * @see pe.com.logistica.negocio.dao.ServicioNegocioDao#calcularCuota(pe.com.logistica.bean.negocio.ServicioAgencia)
   */
  @Override
  public BigDecimal calcularCuota(ServicioAgencia servicioAgencia) throws SQLException {
    BigDecimal resultado = BigDecimal.ZERO;
    Connection conn = null;
    CallableStatement cs = null;
    String sql = "{ ? = call negocio.fn_calcularcuota(?,?,?) }";

    try {
      conn = UtilConexion.obtenerConexion();
      cs = conn.prepareCall(sql);
      int i = 1;
      cs.registerOutParameter(i++, Types.DECIMAL);
      cs.setBigDecimal(i++, servicioAgencia.getMontoTotalServicios());
      cs.setBigDecimal(i++, UtilParse.parseIntABigDecimal(servicioAgencia.getNroCuotas()));
      cs.setBigDecimal(i++, servicioAgencia.getTea());
      cs.execute();

      resultado = cs.getBigDecimal(1);
    } catch (SQLException e) {
      throw new SQLException(e);
    } finally {
      try {
        if (cs != null) {
          cs.close();
        }
        if (conn != null) {
          conn.close();
        }
      } catch (SQLException e) {
        throw new SQLException(e);
      }
    }
    return resultado;
  }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * pe.com.viajes.negocio.dao.ServicioNoviosDao#registrarNovios(pe.com
   * .logistica.bean.negocio.ProgramaNovios)
   */
  @Override
  public Integer registrarNovios(ProgramaNovios programaNovios) throws SQLException {
    Integer codigoNovios = 0;
    Connection conn = null;
    CallableStatement cs = null;
    String sql = "{ ? = call negocio.fn_ingresarprogramanovios(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) }";
    try {
      conn = UtilConexion.obtenerConexion();
      cs = conn.prepareCall(sql);
      int i = 1;
      cs.registerOutParameter(i++, Types.INTEGER);
      cs.setInt(i++, programaNovios.getNovia().getCodigoEntero());
      cs.setInt(i++, programaNovios.getNovio().getCodigoEntero());
      cs.setInt(i++, programaNovios.getDestino().getCodigoEntero());
      cs.setDate(i++, UtilJdbc.convertirUtilDateSQLDate(programaNovios.getFechaBoda()));
      cs.setDate(i++, UtilJdbc.convertirUtilDateSQLDate(programaNovios.getFechaViaje()));
      cs.setInt(i++, programaNovios.getMoneda().getCodigoEntero());
      cs.setBigDecimal(i++, programaNovios.getCuotaInicial());
      cs.setInt(i++, programaNovios.getNroDias());
      cs.setInt(i++, programaNovios.getNroNoches());
      cs.setDate(i++, UtilJdbc.convertirUtilDateSQLDate(programaNovios.getFechaShower()));
      if (StringUtils.isNotBlank(programaNovios.getObservaciones())) {
        cs.setString(i++, programaNovios.getObservaciones());
      } else {
        cs.setNull(i++, Types.VARCHAR);
      }
      cs.setBigDecimal(i++, programaNovios.getMontoTotalServiciosPrograma());
      cs.setInt(i++, programaNovios.getIdServicio());
      cs.setString(i++, programaNovios.getUsuarioCreacion());
      cs.setString(i++, programaNovios.getIpCreacion());
      cs.execute();

      codigoNovios = cs.getInt(1);
    } catch (SQLException e) {
      codigoNovios = 0;
      throw new SQLException(e);
    } finally {
      try {
        if (cs != null) {
          cs.close();
        }
        if (conn != null) {
          conn.close();
        }
      } catch (SQLException e) {
        try {
          if (conn != null) {
            conn.close();
          }
          throw new SQLException(e);
        } catch (SQLException e1) {
          throw new SQLException(e);
        }
      }
    }

    return codigoNovios;
  }
コード例 #3
0
 public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
   checkOpen();
   try {
     _stmt.setBigDecimal(parameterName, x);
   } catch (SQLException e) {
     handleException(e);
   }
 }
コード例 #4
0
 public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
   checkOpen();
   try {
     ((CallableStatement) _stmt).setBigDecimal(parameterName, x);
   } catch (SQLException e) {
     handleException(e);
   }
 }
コード例 #5
0
  /** Sets the bigDecimal */
  @Override
  public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
    try {
      _cstmt.setBigDecimal(parameterName, x);
    } catch (SQLException e) {
      onSqlException(e);

      throw e;
    } catch (RuntimeException e) {
      onRuntimeException(e);

      throw e;
    }
  }
コード例 #6
0
  @Override
  public boolean ingresarServicioNovios(
      ServicioNovios servicioNovios, int idnovios, Connection conexion) throws SQLException {
    boolean resultado = false;
    CallableStatement cs = null;
    String sql = "{ ? = call negocio.fn_ingresarservicionovios(?,?,?,?,?,?,?,?) }";

    try {
      cs = conexion.prepareCall(sql);
      int i = 1;
      cs.registerOutParameter(i++, Types.BOOLEAN);
      cs.setInt(i++, idnovios);
      cs.setInt(i++, servicioNovios.getTipoServicio().getCodigoEntero().intValue());
      cs.setString(i++, servicioNovios.getDescripcionServicio());
      cs.setInt(i++, servicioNovios.getCantidad());
      cs.setBigDecimal(i++, servicioNovios.getPrecioUnitario());
      cs.setBigDecimal(i++, servicioNovios.getTotalServicio());
      cs.setString(i++, servicioNovios.getUsuarioCreacion());
      cs.setString(i++, servicioNovios.getIpCreacion());
      cs.execute();

      resultado = cs.getBoolean(1);
    } catch (SQLException e) {
      resultado = false;
      throw new SQLException(e);
    } finally {
      try {
        if (cs != null) {
          cs.close();
        }
      } catch (SQLException e) {
        throw new SQLException(e);
      }
    }

    return resultado;
  }
コード例 #7
0
  /** @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal) */
  public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {

    original.setBigDecimal(parameterIndex, x);
  }
コード例 #8
0
  /** @see java.sql.CallableStatement#setBigDecimal(java.lang.String, java.math.BigDecimal) */
  public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {

    original.setBigDecimal(parameterName, x);
  }
 public void updateFeeDetail(CFSecurityAuthorization Authorization, CFAccFeeDetailBuff Buff) {
   final String S_ProcName = "updateFeeDetail";
   ResultSet resultSet = null;
   Connection cnx = schema.getCnx();
   CallableStatement stmtUpdateByPKey = null;
   List<CFAccFeeDetailBuff> buffList = new LinkedList<CFAccFeeDetailBuff>();
   try {
     long TenantId = Buff.getRequiredTenantId();
     long FeeId = Buff.getRequiredFeeId();
     long FeeDetailId = Buff.getRequiredFeeDetailId();
     String Description = Buff.getRequiredDescription();
     BigDecimal AmountCharged = Buff.getRequiredAmountCharged();
     int Revision = Buff.getRequiredRevision();
     stmtUpdateByPKey =
         cnx.prepareCall(
             "begin "
                 + schema.getLowerDbSchemaName()
                 + ".upd_feedtl( ?, ?, ?, ?, ?, ?, ?"
                 + ", "
                 + "?"
                 + ", "
                 + "?"
                 + ", "
                 + "?"
                 + ", "
                 + "?"
                 + ", "
                 + "?"
                 + ", "
                 + "? ); end;");
     int argIdx = 1;
     stmtUpdateByPKey.registerOutParameter(argIdx++, OracleTypes.CURSOR);
     stmtUpdateByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtUpdateByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
     stmtUpdateByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
     stmtUpdateByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtUpdateByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
     stmtUpdateByPKey.setString(argIdx++, "FEDT");
     stmtUpdateByPKey.setLong(argIdx++, TenantId);
     stmtUpdateByPKey.setLong(argIdx++, FeeId);
     stmtUpdateByPKey.setLong(argIdx++, FeeDetailId);
     stmtUpdateByPKey.setString(argIdx++, Description);
     stmtUpdateByPKey.setBigDecimal(argIdx++, AmountCharged);
     stmtUpdateByPKey.setInt(argIdx++, Revision);
     stmtUpdateByPKey.execute();
     resultSet = (ResultSet) stmtUpdateByPKey.getObject(1);
     if (resultSet != null) {
       try {
         if (resultSet.next()) {
           CFAccFeeDetailBuff updatedBuff = unpackFeeDetailResultSetToBuff(resultSet);
           if (resultSet.next()) {
             resultSet.last();
             throw CFLib.getDefaultExceptionFactory()
                 .newRuntimeException(
                     getClass(),
                     S_ProcName,
                     "Did not expect multi-record response, "
                         + resultSet.getRow()
                         + " rows selected");
           }
           Buff.setRequiredFeeId(updatedBuff.getRequiredFeeId());
           Buff.setRequiredDescription(updatedBuff.getRequiredDescription());
           Buff.setRequiredAmountCharged(updatedBuff.getRequiredAmountCharged());
           Buff.setRequiredRevision(updatedBuff.getRequiredRevision());
         } else {
           throw CFLib.getDefaultExceptionFactory()
               .newRuntimeException(
                   getClass(),
                   S_ProcName,
                   "Expected a single-record response, " + resultSet.getRow() + " rows selected");
         }
       } catch (SQLException e) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(
                 getClass(), S_ProcName, "upd_feedtl() did not return a valid result cursor");
       } finally {
         if (resultSet != null) {
           try {
             resultSet.close();
           } catch (SQLException e) {
           }
           resultSet = null;
         }
       }
     } else {
       throw CFLib.getDefaultExceptionFactory()
           .newRuntimeException(
               getClass(), S_ProcName, "upd_feedtl() did not return a result cursor");
     }
   } catch (SQLException e) {
     throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
   } finally {
     if (resultSet != null) {
       try {
         resultSet.close();
       } catch (SQLException e) {
       }
       resultSet = null;
     }
     if (stmtUpdateByPKey != null) {
       try {
         stmtUpdateByPKey.close();
       } catch (SQLException e) {
       }
       stmtUpdateByPKey = null;
     }
   }
 }
コード例 #10
0
 public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
   passThru.setBigDecimal(parameterName, x);
 }
コード例 #11
0
  /*
   * prepareStatement
   * This method follows the logic of preparedDataCommon.prepareStatement() except that since it is only
   * called for CFPROCPARAM's it doesn't need to iterate over the data VectorArrayList. Instead it only
   * needs to extract the one value.
   */
  private void prepareStatement(String paramName, CallableStatement CallStatmt, Connection _conn)
      throws dataNotSupportedException, cfmRunTimeException, SQLException {
    // Map the CFML type to a JDBC type
    int jType = getJdbcType(CallStatmt, cfSqlType);

    paramName = paramName.replace("@", "");

    if (passAsNull) {
      // JDBC drivers don't recognize ORACLE_NCLOB so we need to pass it in as a Types.CHAR
      if (jType == ORACLE_NCLOB) CallStatmt.setNull(paramName, Types.CHAR);
      else CallStatmt.setNull(paramName, jType);
      return;
    }

    // Get the value associated with this CFPROCPARAM
    cfData _data = data.get(0);

    switch (jType) {
        // for MS SQL Server via JDBC-ODBC Bridge, if you try to use setString()
        // instead of setObject(), it will pad VARCHAR columns when it shouldn't
      case Types.CHAR:
      case Types.VARCHAR:
        CallStatmt.setObject(paramName, _data.getString(), jType);
        break;

      case Types.LONGVARCHAR:
        CallStatmt.setObject(paramName, _data.getString(), jType);
        break;

      case ORACLE_NCLOB:
        CallStatmt.setObject(paramName, _data.getString(), jType);
        break;

      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        CallStatmt.setObject(paramName, ((cfBinaryData) _data).getByteArray(), jType);
        break;

      case Types.TINYINT:
      case Types.SMALLINT:
      case Types.INTEGER:
        if (_data.getNumber().isInt()) {
          CallStatmt.setInt(paramName, _data.getInt());
          break;
        }
        // if not an int, fall through to next case

      case Types.BIGINT:
        double d = _data.getDouble();
        if (d <= Long.MAX_VALUE) {
          if (isSetLongSupported(_conn)) {
            CallStatmt.setLong(paramName, _data.getLong());
          } else {
            CallStatmt.setDouble(paramName, d);
          }
        } else {
          CallStatmt.setDouble(paramName, d);
        }
        break;

      case Types.DECIMAL:
      case Types.NUMERIC:
        try {
          // NOTE: if a customer is complaining about losing decimal places then make sure they
          // are setting the scale properly in cfqueryparam. The default value for scale
          // is 0 which causes all decimal places to be removed.
          CallStatmt.setBigDecimal(
              paramName,
              new BigDecimal(_data.getDouble()).setScale(scale, BigDecimal.ROUND_HALF_UP));
          break;
        } catch (Exception e) {
          // fall through to next case
        }

      case Types.FLOAT:
      case Types.DOUBLE:
        CallStatmt.setDouble(paramName, _data.getDouble());
        break;

      case Types.REAL:
        CallStatmt.setFloat(paramName, new Float(_data.getDouble()).floatValue());
        break;

      case Types.DATE:
        long date =
            (_data.getDataType() == cfData.CFDATEDATA
                ? _data.getLong()
                : _data.getDateData().getLong());
        try {
          CallStatmt.setDate(paramName, new java.sql.Date(date));
        } catch (SQLException e) { // JDBC-ODBC Bridge doesn't support setDate() for MS SQL Server
          CallStatmt.setString(paramName, com.nary.util.Date.formatDate(date, "dd-MMM-yy"));
        }
        break;

      case Types.TIME:
        long time =
            (_data.getDataType() == cfData.CFDATEDATA
                ? _data.getLong()
                : _data.getDateData().getLong());
        try {
          CallStatmt.setTime(paramName, new java.sql.Time(time));
        } catch (SQLException e) { // JDBC-ODBC Bridge doesn't support setTime() for MS SQL Server
          CallStatmt.setString(paramName, com.nary.util.Date.formatDate(time, "hh:mm aa"));
        }
        break;

      case Types.TIMESTAMP:
        long ts =
            (_data.getDataType() == cfData.CFDATEDATA
                ? _data.getLong()
                : _data.getDateData().getLong());
        CallStatmt.setTimestamp(paramName, new java.sql.Timestamp(ts));
        break;

      case Types.BIT:
        CallStatmt.setBoolean(paramName, _data.getBoolean());
        break;

      case Types.NULL:
        CallStatmt.setNull(paramName, getJdbcType(CallStatmt, cfSqlType));
        break;

      default:
        throw newRunTimeException("Unsupported CFSQLTYPE: " + sqlType);
    }
  }