/**
   * Elimina al registro a través de la entidad dada por vData.
   *
   * <p><b> delete from GRLRegistroPNC where iEjercicio = ? AND iConsecutivoPNC = ? </b>
   *
   * <p><b> Campos Llave: iEjercicio,iConsecutivoPNC, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return boolean - En caso de ser o no eliminado el registro.
   */
  public boolean delete(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    boolean lSuccess = true;
    String cMsg = "";
    try {
      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }

      // Ajustar Where de acuerdo a requerimientos...
      String lSQL = "delete from GRLRegistroPNC where iEjercicio = ? AND iConsecutivoPNC = ?  ";
      // ...

      lPStmt = conn.prepareStatement(lSQL);

      lPStmt.setInt(1, vData.getInt("iEjercicio"));
      lPStmt.setInt(2, vData.getInt("iConsecutivoPNC"));

      lPStmt.executeUpdate();
      if (cnNested == null) {
        conn.commit();
      }
    } catch (SQLException sqle) {
      lSuccess = false;
      cMsg = "" + sqle.getErrorCode();
    } catch (Exception ex) {
      warn("delete", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("delete.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) {
          lPStmt.close();
        }
        if (cnNested == null) {
          if (conn != null) {
            conn.close();
          }
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("delete.close", ex2);
      }
      if (lSuccess == false) throw new DAOException(cMsg);
      return lSuccess;
    }
  }
  /**
   * Inserta el registro dado por la entidad vData.
   *
   * <p><b> insert into
   * TRATiempoTraslado(iCveTramite,iCveModalidad,iCveOficinaOrigen,iCveOficinaDestino,dtIniVigencia,iNumDiasTraslado,lDiasNaturalesTraslado)
   * values (?,?,?,?,?,?,?) </b>
   *
   * <p><b> Campos Llave:
   * iCveTramite,iCveModalidad,iCveOficinaOrigen,iCveOficinaDestino,dtIniVigencia, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return TVDinRep - VO Dinámico que contiene a la entidad a Insertada, así como a la llave de
   *     esta entidad.
   */
  public TVDinRep insert(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    boolean lSuccess = true;
    String cMsg = "";
    try {
      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }
      String lSQL =
          "insert into TRATiempoTraslado(iCveTramite,iCveModalidad,iCveOficinaOrigen,iCveOficinaDestino,dtIniVigencia,iNumDiasTraslado,lDiasNaturalesTraslado) values (?,?,?,?,?,?,?)";

      // AGREGAR AL ULTIMO ...

      vData.addPK(vData.getString("iCveTramite"));
      vData.addPK(vData.getString("iCveModalidad"));
      vData.addPK(vData.getString("iCveOficinaOrigen"));
      vData.addPK(vData.getString("iCveOficinaDestino"));
      vData.addPK(vData.getString("dtIniVigencia"));
      // ...

      lPStmt = conn.prepareStatement(lSQL);
      lPStmt.setInt(1, vData.getInt("iCveTramite"));
      lPStmt.setInt(2, vData.getInt("iCveModalidad"));
      lPStmt.setInt(3, vData.getInt("iCveOficinaOrigen"));
      lPStmt.setInt(4, vData.getInt("iCveOficinaDestino"));
      lPStmt.setDate(5, vData.getDate("dtIniVigencia"));
      lPStmt.setInt(6, vData.getInt("iNumDiasTraslado"));
      lPStmt.setInt(7, vData.getInt("lDiasNaturalesTraslado"));
      lPStmt.executeUpdate();
      if (cnNested == null) {
        conn.commit();
      }
    } catch (SQLException sqle) {
      lSuccess = false;
      cMsg = "" + sqle.getErrorCode();

    } catch (Exception ex) {
      warn("insert", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("insert.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) {
          lPStmt.close();
        }
        if (cnNested == null) {
          if (conn != null) {
            conn.close();
          }
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("insert.close", ex2);
      }
      if (lSuccess == false) throw new DAOException(cMsg);
      return vData;
    }
  }
  /**
   * Actualiza al registro con las modificaciones enviadas sobre la entidad (vData).
   *
   * <p><b> update TRATiempoTraslado set iNumDiasTraslado=?, lDiasNaturalesTraslado=? where
   * iCveTramite = ? AND iCveModalidad = ? AND iCveOficinaOrigen = ? AND iCveOficinaDestino = ? AND
   * dtIniVigencia = ? </b>
   *
   * <p><b> Campos Llave:
   * iCveTramite,iCveModalidad,iCveOficinaOrigen,iCveOficinaDestino,dtIniVigencia, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return TVDinRep - Entidad Modificada.
   */
  public TVDinRep update(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    boolean lSuccess = true;
    try {
      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }
      String lSQL =
          "update TRATiempoTraslado set iNumDiasTraslado=?, lDiasNaturalesTraslado=? where iCveTramite = ? AND iCveModalidad = ? AND iCveOficinaOrigen = ? AND iCveOficinaDestino = ? AND dtIniVigencia = ? ";

      vData.addPK(vData.getString("iCveTramite"));
      vData.addPK(vData.getString("iCveModalidad"));
      vData.addPK(vData.getString("iCveOficinaOrigen"));
      vData.addPK(vData.getString("iCveOficinaDestino"));
      vData.addPK(vData.getString("dtIniVigencia"));

      lPStmt = conn.prepareStatement(lSQL);
      lPStmt.setInt(1, vData.getInt("iNumDiasTraslado"));
      lPStmt.setInt(2, vData.getInt("lDiasNaturalesTraslado"));
      lPStmt.setInt(3, vData.getInt("iCveTramite"));
      lPStmt.setInt(4, vData.getInt("iCveModalidad"));
      lPStmt.setInt(5, vData.getInt("iCveOficinaOrigen"));
      lPStmt.setInt(6, vData.getInt("iCveOficinaDestino"));
      lPStmt.setDate(7, vData.getDate("dtIniVigencia"));
      lPStmt.executeUpdate();
      if (cnNested == null) {
        conn.commit();
      }
    } catch (Exception ex) {
      warn("update", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("update.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) {
          lPStmt.close();
        }
        if (cnNested == null) {
          if (conn != null) {
            conn.close();
          }
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("update.close", ex2);
      }
      if (lSuccess == false) throw new DAOException("");

      return vData;
    }
  }
  /**
   * Elimina al registro a través de la entidad dada por vData.
   *
   * <p><b> delete from TRATiempoTraslado where iCveTramite = ? AND iCveModalidad = ? AND
   * iCveOficinaOrigen = ? AND iCveOficinaDestino = ? AND dtIniVigencia = ? </b>
   *
   * <p><b> Campos Llave:
   * iCveTramite,iCveModalidad,iCveOficinaOrigen,iCveOficinaDestino,dtIniVigencia, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return boolean - En caso de ser o no eliminado el registro.
   */
  public boolean delete(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    boolean lSuccess = true;
    String cMsg = "";
    try {
      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }

      // Ajustar Where de acuerdo a requerimientos...
      String lSQL =
          "delete from TRATiempoTraslado where iCveTramite = ? AND iCveModalidad = ? AND iCveOficinaOrigen = ? AND iCveOficinaDestino = ? AND dtIniVigencia = ?  ";
      // ...

      lPStmt = conn.prepareStatement(lSQL);

      lPStmt.setInt(1, vData.getInt("iCveTramite"));
      lPStmt.setInt(2, vData.getInt("iCveModalidad"));
      lPStmt.setInt(3, vData.getInt("iCveOficinaOrigen"));
      lPStmt.setInt(4, vData.getInt("iCveOficinaDestino"));
      lPStmt.setDate(5, vData.getDate("dtIniVigencia"));

      lPStmt.executeUpdate();
      if (cnNested == null) {
        conn.commit();
      }
    } catch (SQLException sqle) {
      lSuccess = false;
      cMsg = "" + sqle.getErrorCode();
    } catch (Exception ex) {
      warn("delete", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("delete.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) {
          lPStmt.close();
        }
        if (cnNested == null) {
          if (conn != null) {
            conn.close();
          }
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("delete.close", ex2);
      }
      if (lSuccess == false) throw new DAOException(cMsg);
      return lSuccess;
    }
  }
Beispiel #5
0
  public void run() {
    try {

      DbConnection.dbConn();
      // =============================================================================
      int zalogowany = 0;

      System.out.println("Klient sie podlaczyl");

      // LOG
      Pomoc.writeToFile(
          Serwer.LOGDIRECTORY,
          "threadSerwer.log." + d.toLocaleString().substring(0, 10),
          d.toLocaleString() + ": Watek:" + this.getName() + " " + " -> Klient sie podlaczyl");
      // LOG_END

      while (true) { // glowna petla watka

        // wiadomosc = przychodzace.readObject();
        this.reciveObject();
        wiadomosc = this.getPackage();
        Thread.sleep(2000);

        System.out.println("Sprawdzam parafianina");

        if (wiadomosc instanceof User) {

          System.out.println("Przyszla wiadomosc 1");
          if (((User) wiadomosc).getKindQuery() == 0) {

            // LOG
            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient proboje sie zalogowac");
            // LOG_END

            Statement s = null;
            System.out.println("patrze w baze\n");
            try {
              s =
                  DbConnection.conn
                      .createStatement(); // tworzenie obiektu Statement przesylajacego zapytania do
                                          // bazy conn
              ResultSet dane, u;
              u =
                  s.executeQuery(
                      "Select * from Userr"); // wykonanie kwerendy i przeslanie wynikow do obiektu
                                              // ResultSet

              System.out.println(
                  "przyslane: "
                      + ((User) wiadomosc).getLogin()
                      + " "
                      + ((User) wiadomosc).getPassword());
              while (u.next()) {

                String userr = u.getString("LOGIN");
                String passs = u.getString("PASSWORD");
                String userID = u.getString("ID_USERR");

                System.out.println("pobrane z bazy: " + userr + " " + passs);

                Thread.sleep(2000);

                if (((User) wiadomosc).getLogin().equals(userr)
                    && ((User) wiadomosc).getPassword().equals(passs)) { // tymczasowo

                  System.out.println("dane sie zgadzaja\n ZALOGOWANO");

                  ((User) wiadomosc).setRestriction(1);
                  clientRestriction = 1;

                  ((User) wiadomosc).setQuery("OK+");
                  this.sendObject(wiadomosc); // odpowiedz klas¹ user

                  System.out.println("pobieram dane\n");
                  dane = s.executeQuery("Select * from Parishioner where id_userr=" + userID);
                  dane.next();
                  String name = dane.getString("NAME");
                  String surname = dane.getString("SURNAME");
                  String pesel = dane.getString("PESEL");

                  // System.out.println("pobrane dane "+name+""+surname);

                  Parishioner p = new Parishioner();
                  p.setName(name);
                  p.setSurName(surname);
                  p.setPesel(pesel);
                  p.setAdress(new Adress());
                  p.setRestriction(clientRestriction);
                  p.setQuery("OK+");

                  Thread.sleep(2000);
                  this.sendObject(p); // odpowiedz klas¹ parishioner

                  // LOG
                  Pomoc.writeToFile(
                      Serwer.LOGDIRECTORY,
                      "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                      d.toLocaleString()
                          + ": Watek:"
                          + this.getName()
                          + " "
                          + " -> Klient sie zalogowal");
                  // LOG_END

                  zalogowany = 1;
                }
              }
              if (zalogowany == 0) { // kiedy haslo/login jest zly
                System.out.println("doszlo do konca i wysyla err");
                ((User) wiadomosc).setQuery("ERR");
                this.sendObject(wiadomosc);
              }
            } catch (SQLException e) {
              System.out.println("Blad odczytu z bazy! " + e.toString());
              System.exit(3);
            }
          } // koniec logowania
        } else // konice usera
        if (wiadomosc instanceof Parishioner) {

          if (((Parishioner) wiadomosc).getKindQuery() == -1) {

            ((Parishioner) wiadomosc).setRestriction(0);
            ((Parishioner) wiadomosc).setData("Wylogowano CIE");
            ((Parishioner) wiadomosc).setQuery("OK+");
            this.sendObject(wiadomosc);

            // LOG
            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient sie wylogowal");
            // LOG_END

          } // koniec wylogowywania
        } else if (wiadomosc instanceof Order) {

          /*---------------*/ if (((Order) wiadomosc).getKindQuery() == 1) { // dodanie do bazy
            System.out.println("Przyszla wiadomosc 2"); // tymczasem
            System.out.println(
                "Zamowienie zlozyl: "
                    + ((Order) wiadomosc).getSenderPesel()
                    + " "
                    + ((Order) wiadomosc).getEvent()
                    + "\n"
                    + "Odprawia "
                    + ((Order) wiadomosc).getExecutroPesel()
                    + " Kiedy: "
                    + ((Order) wiadomosc).getBeginDate());

            String sPesel = ((Order) wiadomosc).getSenderPesel();
            String ePesel = ((Order) wiadomosc).getExecutroPesel();
            String event = ((Order) wiadomosc).getEvent();
            String describe = ((Order) wiadomosc).getDescribe();
            Date bDate = ((Order) wiadomosc).getBeginDate();
            Date eDate = ((Order) wiadomosc).getEndDate();

            Statement dod = null;
            dod = DbConnection.conn.createStatement();
            // String dodaj=("insert into orderr values
            // (6,"+event+","+ePesel+","+sPesel+","+describe+"," +
            // "to_date('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'),to_date('2003/05/04
            // 21:02:44', 'yyyy/mm/dd hh24:mi:ss'))");

            String dodaj =
                "INSERT INTO orderr (id_orderr,id_event,odprawiajacy_pesel,zamawiajacy_pesel,describe) VALUES"
                    + "(4,"
                    + event
                    + ","
                    + ePesel
                    + ","
                    + sPesel
                    + ",'"
                    + describe
                    + "')"; // ,to_date('2003/05/03 21:02:44', 'yyyy/mm/dd)";

            // int nr=6;
            // String dodaj="Insert into test1 (id) values"+"("+nr+")";
            System.out.println("zapisuje dane\n");
            try {
              int insertedRows = dod.executeUpdate(dodaj);
              if (insertedRows != 0) System.out.println("dodano");
              else System.out.println("nie dodano");
            } catch (SQLException e1) {

              e1.printStackTrace();
            }

            ((Order) wiadomosc).setData("ZAMOWIENIE ZLOZONE");
            ((Order) wiadomosc).setQuery("OK+");
            Thread.sleep(2000);
            this.sendObject(wiadomosc);

            // LOG
            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient zlozyl zamowienie (wyslano)");
            // LOG_END
          } // koniec skladania zamowienia

          /*--------------*/ if (((Order) wiadomosc).getKindQuery() == 4) { // select z bazy

            LinkedList<Order> orderList = new LinkedList<Order>();

            for (int i = 0; i < 50; i++) orderList.add(new Order());
            orderList.getFirst().setQuery("OK+");
            this.sendObject(orderList);

            Pomoc.writeToFile(
                Serwer.LOGDIRECTORY,
                "threadSerwer.log." + d.toLocaleString().substring(0, 10),
                d.toLocaleString()
                    + ": Watek:"
                    + this.getName()
                    + " "
                    + " -> Klient pobral liste zamowien");
          } // koniec wysylania listy zamowien (docelowo po odczycie z bazy)

        } else System.out.println("Nie rozpoznano");
      }
    } catch (Exception e) {
      System.out.println("Klient sie --odlaczyl");
    } finally {

      try {

        socket.close(); // zamkniecie polaczenia

      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  /**
   * Inserta el registro dado por la entidad vData.
   *
   * <p><b> insert into
   * GRLRegistroPNC(iEjercicio,iConsecutivoPNC,dtRegistro,iCveUsuRegistro,iCveProducto,lResuelto,dtResolucion,iCveOficinaAsignado,iCveDeptoAsignado)
   * values (?,?,?,?,?,?,?,?,?) </b>
   *
   * <p><b> Campos Llave: iEjercicio,iConsecutivoPNC, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return TVDinRep - VO Dinámico que contiene a la entidad a Insertada, así como a la llave de
   *     esta entidad.
   */
  public TVDinRep insert(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    boolean lSuccess = true;
    TFechas dtFechaActual = new TFechas();

    try {
      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }
      String lSQL =
          "insert into GRLRegistroPNC(iEjercicio,iConsecutivoPNC,dtRegistro,iCveUsuRegistro,iCveProducto,lResuelto,dtResolucion,iCveOficinaAsignado,iCveDeptoAsignado,iCveOficina,iCveDepartamento,iCveProceso) values (?,?,?,?,?,?,?,?,?,?,?,?)";

      // AGREGAR AL ULTIMO ...
      Vector vcData =
          findByCustom(
              "",
              "select MAX(iConsecutivoPNC) AS iConsecutivoPNC from GRLRegistroPNC WHERE iEjercicio = "
                  + vData.getInt("iEjercicio"));
      if (vcData.size() > 0) {
        TVDinRep vUltimo = (TVDinRep) vcData.get(0);
        vData.put("iConsecutivoPNC", vUltimo.getInt("iConsecutivoPNC") + 1);
      } else vData.put("iConsecutivoPNC", 1);
      vData.addPK(vData.getString("iConsecutivoPNC"));
      lPStmt = conn.prepareStatement(lSQL);
      lPStmt.setInt(1, dtFechaActual.getIntYear(dtFechaActual.TodaySQL()));
      lPStmt.setInt(2, vData.getInt("iConsecutivoPNC"));
      iConsecutivo = vData.getInt("iConsecutivoPNC");
      lPStmt.setDate(3, tFecha.TodaySQL());
      lPStmt.setInt(4, vData.getInt("iCveUsuario"));
      lPStmt.setInt(5, vData.getInt("iCveProducto"));
      lPStmt.setInt(6, vData.getInt("lResuelto"));
      if (vData.getDate("dtResolucion") == null) lPStmt.setNull(7, Types.DATE);
      else lPStmt.setDate(7, vData.getDate("dtResolucion"));
      lPStmt.setInt(8, vData.getInt("iCveOficinaUsrAsg"));
      lPStmt.setInt(9, vData.getInt("iCveDeptoUsrAsg"));
      lPStmt.setInt(10, vData.getInt("iCveOficinaUsr"));
      lPStmt.setInt(11, vData.getInt("iCveDeptoUsr"));
      lPStmt.setInt(12, vData.getInt("iCveProceso"));

      lPStmt.executeUpdate();
      lPStmt.close();
      try {
        TDGRLRegCausaPNC1 dGRLRegCausaPNC = new TDGRLRegCausaPNC1();
        dGRLRegCausaPNC.insert(vData, conn, iConsecutivo);
      } catch (Exception exCausa) {
        exCausa.printStackTrace();
        lSuccess = false;
        throw new Exception("Error Causa");
      }
      if (cnNested == null && lSuccess) conn.commit();
    } catch (Exception ex) {
      warn("insert", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("insert.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) lPStmt.close();
        if (cnNested == null) {
          if (conn != null) conn.close();
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("insert.close", ex2);
      }
      if (lSuccess == false) throw new DAOException("");
      return vData;
    }
  }
  /**
   * Actualiza el campo de Producto No Conforme de la persona que recibe la notificación.
   *
   * <p><b> update GRLRegistroPNC set cRecibeNotif=? where iEjercicio = ? AND iConsecutivoPNC = ?
   * </b>
   *
   * <p><b> Campos Llave: iEjercicio,iConsecutivoPNC, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return TVDinRep - Entidad Modificada.
   */
  public TVDinRep updateRecibe(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    int iConsecutivoPNC = 0, iEjercicioPNC = 0;
    boolean lSuccess = true;
    try {

      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }
      Vector vcPNC =
          findByCustom(
              "",
              "SELECT "
                  + "iEjercicioPNC,ICONSECUTIVOPNC "
                  + "FROM TRAREGPNCETAPA "
                  + "where IEJERCICIO = "
                  + vData.getInt("iEjercicio")
                  + " and INUMSOLICITUD = "
                  + vData.getInt("iNumSolicitud")
                  + " order by iorden desc");
      if (vcPNC.size() > 0) {
        TVDinRep vRegPNC = (TVDinRep) vcPNC.get(0);
        iConsecutivoPNC = vRegPNC.getInt("ICONSECUTIVOPNC");
        iEjercicioPNC = vRegPNC.getInt("iEjercicioPNC");
      }

      String lSQL =
          "update GRLRegistroPNC set cRecibeNotif=?,dtNotificacion=? where iEjercicio = ? AND iConsecutivoPNC = ? ";

      lPStmt = conn.prepareStatement(lSQL);
      lPStmt.setString(1, vData.getString("cRecibeNotif"));
      lPStmt.setDate(2, vData.getDate("dtNotificacion"));
      lPStmt.setInt(3, iEjercicioPNC);
      lPStmt.setInt(4, iConsecutivoPNC);

      if (cnNested == null) {
        conn.commit();
      }

      /*if(cnNested == null){
        conn.commit();
        TDVerificacion tdVer = new TDVerificacion();
        tdVer.upNotificacion(vData, cnNested);
      }*/
    } catch (Exception ex) {
      warn("update", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("update.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) {
          lPStmt.close();
        }
        if (cnNested == null) {
          if (conn != null) {
            conn.close();
          }
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("update.close", ex2);
      }
      if (lSuccess == false) throw new DAOException("");

      return vData;
    }
  }
  /**
   * Actualiza al registro con las modificaciones enviadas sobre la entidad (vData).
   *
   * <p><b> update GRLRegistroPNC set dtRegistro=?, iCveUsuRegistro=?, iCveProducto=?, lResuelto=?,
   * dtResolucion=?, iCveOficinaAsignado=?, iCveDeptoAsignado=? where iEjercicio = ? AND
   * iConsecutivoPNC = ? </b>
   *
   * <p><b> Campos Llave: iEjercicio,iConsecutivoPNC, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return TVDinRep - Entidad Modificada.
   */
  public TVDinRep update(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    boolean lSuccess = true;
    try {
      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }
      String lSQL =
          "update GRLRegistroPNC set dtRegistro=?, iCveUsuRegistro=?, iCveProducto=?, lResuelto=?, dtResolucion=?, iCveOficinaAsignado=?, iCveDeptoAsignado=? where iEjercicio = ? AND iConsecutivoPNC = ? ";

      vData.addPK(vData.getString("iEjercicio"));
      vData.addPK(vData.getString("iConsecutivoPNC"));

      lPStmt = conn.prepareStatement(lSQL);
      lPStmt.setDate(1, vData.getDate("dtRegistro"));
      lPStmt.setInt(2, vData.getInt("iCveUsuRegistro"));
      lPStmt.setInt(3, vData.getInt("iCveProducto"));
      lPStmt.setInt(4, vData.getInt("lResuelto"));
      lPStmt.setDate(5, vData.getDate("dtResolucion"));
      lPStmt.setInt(6, vData.getInt("iCveOficinaAsignado"));
      lPStmt.setInt(7, vData.getInt("iCveDeptoAsignado"));
      lPStmt.setInt(8, vData.getInt("iEjercicio"));
      lPStmt.setInt(9, vData.getInt("iConsecutivoPNC"));
      lPStmt.executeUpdate();
      if (cnNested == null) {
        conn.commit();
      }
    } catch (Exception ex) {
      warn("update", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("update.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) {
          lPStmt.close();
        }
        if (cnNested == null) {
          if (conn != null) {
            conn.close();
          }
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("update.close", ex2);
      }
      if (lSuccess == false) throw new DAOException("");

      return vData;
    }
  }
  /**
   * Inserta el registro dado por la entidad vData.
   *
   * <p><b> insert into
   * GRLRegistroPNC(iEjercicio,iConsecutivoPNC,dtRegistro,iCveUsuRegistro,iCveProducto,lResuelto,dtResolucion,iCveOficinaAsignado,iCveDeptoAsignado)
   * values (?,?,?,?,?,?,?,?,?) </b>
   *
   * <p><b> Campos Llave: iEjercicio,iConsecutivoPNC, </b>
   *
   * @param vData TVDinRep - VO Dinámico que contiene a la entidad a Insertar.
   * @param cnNested Connection - Conexión anidada que permite que el método se encuentre dentro de
   *     una transacción mayor.
   * @throws DAOException - Excepción de tipo DAO
   * @return TVDinRep - VO Dinámico que contiene a la entidad a Insertada, así como a la llave de
   *     esta entidad.
   */
  public TVDinRep insertExiste(TVDinRep vData, Connection cnNested) throws DAOException {
    DbConnection dbConn = null;
    Connection conn = cnNested;
    PreparedStatement lPStmt = null;
    boolean lSuccess = true;
    boolean lAgregarAPNC = false;
    boolean lInsertaCausa = false;
    TFechas dtFechaActual = new TFechas();
    int iNumSolicitud, iCveTramite, iCveModalidad = 0;
    int iConsecutivoPNC = 0;
    int iEjercicio = 0;
    try {
      // LEL26092006
      Vector vcDataA =
          findByCustom(
              "",
              "SELECT "
                  + "TRAREGPNCETAPA.IEJERCICIOPNC, "
                  + "TRAREGPNCETAPA.INUMSOLICITUD, "
                  + "TRAREGPNCETAPA.ICONSECUTIVOPNC, "
                  + "TRAREGPNCETAPA.ICVETRAMITE, "
                  + "TRAREGPNCETAPA.ICVEMODALIDAD "
                  + "FROM TRAREGPNCETAPA "
                  + "where TRAREGPNCETAPA.IEJERCICIO = "
                  + vData.getInt("iEjercicio")
                  + " and TRAREGPNCETAPA.INUMSOLICITUD = "
                  + vData.getInt("iNumSolicitud")
                  + " ORDER BY ICONSECUTIVOPNC DESC ");
      TVDinRep vSoli;
      if (vcDataA.size() > 0) {
        vSoli = (TVDinRep) vcDataA.get(0);
        iEjercicio = vSoli.getInt("IEJERCICIOPNC");
        iNumSolicitud = vSoli.getInt("INUMSOLICITUD");
        iConsecutivoPNC = vSoli.getInt("ICONSECUTIVOPNC");
        iCveTramite = vSoli.getInt("ICVETRAMITE");
        iCveModalidad = vSoli.getInt("ICVEMODALIDAD");
        vcDataA = null;
        vcDataA =
            findByCustom(
                "",
                "SELECT "
                    + "DTNOTIFICACION FROM TRAREGREQXTRAM "
                    + "WHERE IEJERCICIO = "
                    + iEjercicio
                    + " AND INUMSOLICITUD = "
                    + iNumSolicitud
                    + " AND ICVETRAMITE = "
                    + iCveTramite
                    + " AND ICVEMODALIDAD = "
                    + iCveModalidad
                    + " AND LTIENEPNC = 1");
        lAgregarAPNC = true;
        for (int i = 0; i < vcDataA.size() && lAgregarAPNC == false; i++) {
          vSoli = (TVDinRep) vcDataA.get(i);
          if (vSoli.getDate("DTNOTIFICACION") == null) lAgregarAPNC = true;
          else lAgregarAPNC = false;
        }
      }
      if (lAgregarAPNC) {
        TVDinRep vResuelto;
        Vector vcDataR =
            findByCustom(
                "",
                "SELECT lResuelto "
                    + "FROM GRLREGISTROPNC WHERE "
                    + "IEJERCICIO = "
                    + iEjercicio
                    + " AND ICONSECUTIVOPNC = "
                    + iConsecutivoPNC);
        if (vcDataR.size() > 0) {
          vResuelto = (TVDinRep) vcDataR.get(0);
          if (vResuelto.getInt("lResuelto") != 0) lAgregarAPNC = false;
        }
      }
      // FinLEL26092006
      if (cnNested == null) {
        dbConn = new DbConnection(dataSourceName);
        conn = dbConn.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(2);
      }
      String lSQL =
          "insert into GRLRegistroPNC(iEjercicio,iConsecutivoPNC,dtRegistro,iCveUsuRegistro,iCveProducto,lResuelto,dtResolucion,iCveOficinaAsignado,iCveDeptoAsignado,iCveOficina,iCveDepartamento,iCveProceso) values (?,?,?,?,?,?,?,?,?,?,?,?)";

      // AGREGAR AL ULTIMO ...
      if (lAgregarAPNC == false) {
        Vector vcData =
            findByCustom(
                "",
                "select MAX(iConsecutivoPNC) AS iConsecutivoPNC from GRLRegistroPNC WHERE iEjercicio = "
                    + vData.getInt("iEjercicio"));
        if (vcData.size() > 0) {
          TVDinRep vUltimo = (TVDinRep) vcData.get(0);
          vData.put("iConsecutivoPNC", vUltimo.getInt("iConsecutivoPNC") + 1);
        } else vData.put("iConsecutivoPNC", 1);
      } else {
        vData.put("iConsecutivoPNC", iConsecutivoPNC);
      }
      vData.addPK(vData.getString("iConsecutivoPNC"));
      lPStmt = conn.prepareStatement(lSQL);
      lPStmt.setInt(1, dtFechaActual.getIntYear(dtFechaActual.TodaySQL()));
      lPStmt.setInt(2, vData.getInt("iConsecutivoPNC"));
      iConsecutivo = vData.getInt("iConsecutivoPNC");
      lPStmt.setDate(3, tFecha.TodaySQL());
      lPStmt.setInt(4, vData.getInt("iCveUsuario"));
      lPStmt.setInt(5, vData.getInt("iCveProducto"));
      lPStmt.setInt(6, vData.getInt("lResuelto"));
      if (vData.getDate("dtResolucion") == null) lPStmt.setNull(7, Types.DATE);
      else lPStmt.setDate(7, vData.getDate("dtResolucion"));
      lPStmt.setInt(8, vData.getInt("iCveOficinaUsrAsg"));
      lPStmt.setInt(9, vData.getInt("iCveDeptoUsrAsg"));
      lPStmt.setInt(10, vData.getInt("iCveOficinaUsr"));
      lPStmt.setInt(11, vData.getInt("iCveDeptoUsr"));
      lPStmt.setInt(12, vData.getInt("iCveProceso"));

      if (lAgregarAPNC == false) lPStmt.executeUpdate();
      lPStmt.close();
      try {
        TDGRLRegCausaPNC1 dGRLRegCausaPNC = new TDGRLRegCausaPNC1();
        //    TDGRLRegCausaPNC dGRLRegCausaPNC = new TDGRLRegCausaPNC();
        if (lAgregarAPNC == false) {
          dGRLRegCausaPNC.insert(vData, conn, iConsecutivo);
          //   dGRLRegCausaPNC.insert(vData,conn);
        } else {
          dGRLRegCausaPNC.insertA(vData, conn, iConsecutivo);
          //   dGRLRegCausaPNC.insertA(vData,conn);
        }
      } catch (Exception exCausa) {
        exCausa.printStackTrace();
        lSuccess = false;
      }
      if (cnNested == null && lSuccess) conn.commit();
    } catch (Exception ex) {
      warn("insert", ex);
      if (cnNested == null) {
        try {
          conn.rollback();
        } catch (Exception e) {
          fatal("insert.rollback", e);
        }
      }
      lSuccess = false;
    } finally {
      try {
        if (lPStmt != null) lPStmt.close();
        if (cnNested == null) {
          if (conn != null) conn.close();
          dbConn.closeConnection();
        }
      } catch (Exception ex2) {
        warn("insert.close", ex2);
      }
      if (lSuccess == false) throw new DAOException("");
      return vData;
    }
  }