示例#1
0
  public void grabarPortal(Integer idusuario, Collection<Servicio> servicios) throws DAOException {
    log.info("grabarPortal(" + idusuario + ", " + servicios + ")");
    Connection cons = null;
    PreparedStatement stmt = null;
    try {
      String query =
          "update cv_servicio_usuario set columna=?, posicion=? where idusuario=? and idservicio=?";
      cons = dataSource.getConnection();
      cons.setAutoCommit(false);
      stmt = cons.prepareStatement(query);
      stmt.setInt(3, idusuario);

      for (Servicio servicio : servicios) {
        stmt.setInt(1, servicio.getColumna());
        stmt.setInt(2, servicio.getPosicion());
        stmt.setString(4, servicio.getId());
        if (stmt.executeUpdate() != 1) {
          throw new DAOException(
              "No se pudo actualizar: " + servicio.getId() + "-" + servicio.getPosicion());
        }
      }
      cons.commit();
    } catch (SQLException e) {
      log.error(e);
      throw new DAOException(e.toString());
    } catch (Exception e) {
      log.error(e);
      throw new DAOException(e.toString());
    } finally {
      try {
        cons.rollback();
      } catch (SQLException e) {
      }
      closeStatement(stmt);
      closeConnection(cons);
    }
  }