/** Inserts a new row in the carrito_compras table. */
  public CarritoComprasPk insert(CarritoCompras dto) throws CarritoComprasDaoException {
    long t1 = System.currentTimeMillis();
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      // get the user-specified connection or get a connection from the ResourceManager
      conn = isConnSupplied ? userConn : ResourceManager.getConnection();

      stmt = conn.prepareStatement(SQL_INSERT);
      int index = 1;
      stmt.setString(index++, dto.getIdCarrito());
      stmt.setDouble(index++, dto.getTotal());
      stmt.setDouble(index++, dto.getSubtotal());
      stmt.setDouble(index++, dto.getImpuestos());
      System.out.println("Executing " + SQL_INSERT + " with DTO: " + dto);
      int rows = stmt.executeUpdate();
      long t2 = System.currentTimeMillis();
      System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)");
      reset(dto);
      return dto.createPk();
    } catch (Exception _e) {
      _e.printStackTrace();
      throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e);
    } finally {
      ResourceManager.close(stmt);
      if (!isConnSupplied) {
        ResourceManager.close(conn);
      }
    }
  }
  /** Deletes a single row in the carrito_compras table. */
  public void delete(CarritoComprasPk pk) throws CarritoComprasDaoException {
    long t1 = System.currentTimeMillis();
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;

    try {
      // get the user-specified connection or get a connection from the ResourceManager
      conn = isConnSupplied ? userConn : ResourceManager.getConnection();

      System.out.println("Executing " + SQL_DELETE + " with PK: " + pk);
      stmt = conn.prepareStatement(SQL_DELETE);
      stmt.setString(1, pk.getIdCarrito());
      int rows = stmt.executeUpdate();
      long t2 = System.currentTimeMillis();
      System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)");
    } catch (Exception _e) {
      _e.printStackTrace();
      throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e);
    } finally {
      ResourceManager.close(stmt);
      if (!isConnSupplied) {
        ResourceManager.close(conn);
      }
    }
  }
  /**
   * Returns all rows from the carrito_compras table that match the specified arbitrary SQL
   * statement
   */
  public CarritoCompras[] findByDynamicWhere(String sql, Object[] sqlParams)
      throws CarritoComprasDaoException {
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      // get the user-specified connection or get a connection from the ResourceManager
      conn = isConnSupplied ? userConn : ResourceManager.getConnection();

      // construct the SQL statement
      final String SQL = SQL_SELECT + " WHERE " + sql;

      System.out.println("Executing " + SQL);
      // prepare statement
      stmt = conn.prepareStatement(SQL);
      stmt.setMaxRows(maxRows);

      // bind parameters
      for (int i = 0; sqlParams != null && i < sqlParams.length; i++) {
        stmt.setObject(i + 1, sqlParams[i]);
      }

      rs = stmt.executeQuery();

      // fetch the results
      return fetchMultiResults(rs);
    } catch (Exception _e) {
      _e.printStackTrace();
      throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e);
    } finally {
      ResourceManager.close(rs);
      ResourceManager.close(stmt);
      if (!isConnSupplied) {
        ResourceManager.close(conn);
      }
    }
  }