示例#1
0
 public void close() {
   try {
     basicstmt.close();
     DatabaseFactory.freeConnection(corecxn);
     DatabaseFactory.freeConnection(chipcxn);
     corecxn = null;
     chipcxn = null;
     basicstmt = null;
   } catch (SQLException e) {
     throw new DatabaseException(e.toString(), e);
   }
 }
  /**
   * @param pagos List
   * @param montoaAbonar double
   * @return int 1, finalizar nota entregar articulos y entregar articulos
   */
  public java.util.List<Pago> agregarPagos(List<Pago> pagos, double montoaAbonar) {
    try {

      pagos = DaoVentas.registrarPagos(ventaSeleccionada.getId(), pagos, null);
      // Registramos los pagos, ahora revisamos si es necesario finalizar la nota checando el monto
      // pendiente
      if ((montoPendiente - montoaAbonar) <= 0.05) {
        // Se han registrado los pagos suficientes para finalizar la nota
        DaoVentas.finalizarVenta(this.ventaSeleccionada);
      }
      return pagos;
    } catch (SQLException ex) {
      System.out.println(ex.toString());
      return null;
    }
  }
  /** Method declaration */
  void testPerformance() {

    String all = txtCommand.getText();
    StringBuffer b = new StringBuffer();
    long total = 0;

    for (int i = 0; i < all.length(); i++) {
      char c = all.charAt(i);

      if (c != '\n') {
        b.append(c);
      }
    }

    all = b.toString();

    String g[] = new String[4];

    g[0] = "ms";
    g[1] = "count";
    g[2] = "sql";
    g[3] = "error";

    gResult.setHead(g);

    int max = 1;

    lTime = System.currentTimeMillis() - lTime;

    while (!all.equals("")) {
      int i = all.indexOf(';');
      String sql;

      if (i != -1) {
        sql = all.substring(0, i);
        all = all.substring(i + 1);
      } else {
        sql = all;
        all = "";
      }

      if (sql.startsWith("--#")) {
        max = Integer.parseInt(sql.substring(3));

        continue;
      } else if (sql.startsWith("--")) {
        continue;
      }

      g[2] = sql;

      long l = 0;

      try {
        l = DatabaseManagerCommon.testStatement(sStatement, sql, max);
        total += l;
        g[0] = String.valueOf(l);
        g[1] = String.valueOf(max);
        g[3] = "";
      } catch (SQLException e) {
        g[0] = g[1] = "n/a";
        g[3] = e.toString();
      }

      gResult.addRow(g);
      System.out.println(l + " ms : " + sql);
    }

    g[0] = "" + total;
    g[1] = "total";
    g[2] = "";

    gResult.addRow(g);

    lTime = System.currentTimeMillis() - lTime;

    updateResult();
  }
  private void executeParsedFile(NameListMessage nameListMessage, ArrayList cmds) {
    BufferedWriter buffer = null;
    int connectionId = nameListMessage.connectionId;
    boolean commaSeparated = nameListMessage.commaSeparated;

    // get java.sql.Connection from connectionId
    Connection connection = ConnectionService.getConnection(connectionId);

    if (connection == null) {
      nameListMessage.errorMessage = kConnectionClosed;
    } else {

      try {
        Thread th = null;
        buffer = new BufferedWriter(writer);

        // if reader exists, create reading thread
        if (reader != null) {
          final ObjectNameReader objectReader = new ObjectNameReader(nameListMessage.nameList);

          // This thread will read stream until meets EOL (ie. when
          // writer is closed)
          th =
              new Thread() {
                public void run() {
                  objectReader.readInputFile(reader);
                }
              };
        } // end if

        // if no reader (offline reverse), never start the reading
        // thread
        // (because output is written down directly to the disk without
        // processing in counterpart).
        if (reader != null) th.start();

        // execute each SQL statement
        // we skip objects that don't need to be reversed
        Iterator iter = cmds.iterator();
        int index = -1;
        while (iter.hasNext()) {
          String cmd = (String) iter.next();
          index++;
          // check if this statement id is marked as <to skip>
          if (nameListMessage.ignoredStatementIds != null
              && nameListMessage.ignoredStatementIds.contains(new Integer(index))) {
            if (commaSeparated) {
              buffer.flush();
              buffer.newLine();
            }
            continue;
          }
          if (writer != null) {
            if (cmd != null) {
              try {
                execute(connection, cmd, buffer, commaSeparated);
              } catch (SQLException e) {
                if (Debug.isDebug()) e.printStackTrace();
                nameListMessage.errorMessage =
                    nameListMessage.errorMessage == null
                        ? e.toString()
                        : nameListMessage.errorMessage.concat("\n" + e.toString()); // NOT
                // LOCALIZABLE,
                // escape
                // code
              }
            }
            if (commaSeparated) {
              buffer.flush();
              buffer.newLine();
            }
          }
        }
      }
      /*
       * catch (SQLException ex) { if (Debug.isDebug()) ex.printStackTrace();
       * nameListMessage.errorMessage = nameListMessage.errorMessage == null ? ex.toString() :
       * nameListMessage.errorMessage.concat("\n" + ex.toString()); //NOT LOCALIZABLE, escape
       * code }
       */
      catch (IOException ex) {
        if (Debug.isDebug()) ex.printStackTrace();
        nameListMessage.errorMessage =
            nameListMessage.errorMessage == null
                ? ex.toString()
                : nameListMessage.errorMessage.concat(
                    "\n" + ex.toString()); // NOT LOCALIZABLE, escape
        // code
      }

      // close writer: the reading thread terminates.
      try {
        // WARNING: we must make a pause after closing the buffer
        // otherwise
        // the nameList variable won't be well initialized...strange!
        // [FG]
        buffer.close();
        Thread.sleep(400);
      } catch (IOException ex) {
      } catch (InterruptedException ex) {
      }
    } // end if
  } // end parseSqlFile()
示例#5
0
  public void go(SystemEnvironment sysEnv) throws SDMSException {
    Long sgId = null;
    Long ZERO = new Long(0);

    if (!sysEnv.cEnv.gid().contains(SDMSObject.adminGId)) {
      SDMSPrivilege p = new SDMSPrivilege();
      Vector v = SDMSMemberTable.idx_uId.getVector(sysEnv, sysEnv.cEnv.uid());
      for (int i = 0; i < v.size(); i++) {
        SDMSMember m = (SDMSMember) v.get(i);
        try {
          SDMSGrant gr =
              SDMSGrantTable.idx_objectId_gId_getUnique(
                  sysEnv, new SDMSKey(ZERO, m.getGId(sysEnv)));
          p.addPriv(sysEnv, gr.getPrivs(sysEnv).longValue());
        } catch (NotFoundException nfe) {

        }
      }
      try {
        if (sysEnv.selectGroup != null) {
          SDMSGroup sg = SDMSGroupTable.idx_name_getUnique(sysEnv, sysEnv.selectGroup);
          sgId = sg.getId(sysEnv);
        }
      } catch (NotFoundException nfe) {

      }
      if (!(p.can(SDMSPrivilege.MANAGE_SEL) || (sgId != null && sysEnv.cEnv.gid().contains(sgId))))
        throw new AccessViolationException(
            new SDMSMessage(sysEnv, "03003081235", "Insufficient Privileges"));
    }

    int read = 0;
    SDMSOutputContainer d_container = null;

    if (cl_size > 0) {
      clist = new int[cl_size];
      ctype = new int[cl_size];
    }

    try {
      Statement stmt = sysEnv.dbConnection.createStatement();
      ResultSet rset = stmt.executeQuery(selectCmd);
      ResultSetMetaData mdset = rset.getMetaData();
      Vector desc = collist(mdset);
      d_container = new SDMSOutputContainer(sysEnv, "Selected Values", desc);
      while (rset.next()) {
        Vector data = new Vector();
        int j = 0;
        for (int i = 1; i <= desc.size(); i++) {
          Object o = rset.getObject(i);
          if (cl_size > 0 && j < cl_size && i == clist[j]) {
            o = convert(sysEnv, o, j);
            j++;
          }
          data.addElement((rset.wasNull() ? null : o));
        }
        d_container.addData(sysEnv, data);
        read++;
      }
      stmt.close();
      sysEnv.dbConnection.commit();
    } catch (SQLException sqle) {

      try {

        sysEnv.dbConnection.rollback();
      } catch (SQLException sqle2) {

        throw new RecoverableException(new SDMSMessage(sysEnv, "03310281524", "Connection lost"));
      }

      throw new CommonErrorException(
          new SDMSMessage(sysEnv, "03204170024", "SQL Error : $1", sqle.toString()));
    }

    if (sv != null && sv.size() > 0) {
      int sca[] = new int[sv.size()];
      for (int i = 0; i < sv.size(); i++) {
        sca[i] = ((Integer) sv.get(i)).intValue();
        if (sca[i] >= d_container.columns)
          throw new CommonErrorException(
              new SDMSMessage(
                  sysEnv,
                  "03003081227",
                  "The sort column specified ($1) exceeds the number of columns in the output",
                  new Integer(sca[i])));
      }
      Collections.sort(d_container.dataset, d_container.getComparator(sysEnv, sca));
    }

    result.setOutputContainer(d_container);
    result.setFeedback(
        new SDMSMessage(sysEnv, "03204112153", "$1 Row(s) selected", new Integer(read)));
  }