Ejemplo n.º 1
0
  // @SuppressWarnings("unchecked")
  public void checkForOutgoingMessages() throws Exception {
    Statement sqlCmd1, sqlCmd2;
    ResultSet rs;
    LinkedList messageList = new LinkedList();
    COutgoingMessage message;
    int batchLimit;

    batchLimit = settings.getPhoneSettings().getBatchOutgoing();
    sqlCmd1 =
        connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs = sqlCmd1.executeQuery("select count(*) as cnt from sms_out where dispatch_date is null");
    rs.next();
    if (rs.getInt("cnt") != 0) {
      rs.close();
      sqlCmd2 = connection.createStatement();
      rs = sqlCmd1.executeQuery("select * from sms_out where dispatch_date is null");
      while (rs.next()) {
        if (messageList.size() > batchLimit) break;
        message =
            new COutgoingMessage(rs.getString("recipient").trim(), rs.getString("text").trim());
        message.setId("" + rs.getInt("id"));
        message.setFlashSms(rs.getInt("flash_sms") == 1);
        message.setStatusReport(rs.getInt("status_report") == 1);
        message.setSourcePort(rs.getInt("src_port"));
        message.setDestinationPort(rs.getInt("dst_port"));
        message.setValidityPeriod(rs.getInt("validity_period"));
        if (settings.getPhoneSettings().getMessageEncoding().equalsIgnoreCase("7bit"))
          message.setMessageEncoding(CMessage.MessageEncoding.Enc7Bit);
        else if (settings.getPhoneSettings().getMessageEncoding().equalsIgnoreCase("8bit"))
          message.setMessageEncoding(CMessage.MessageEncoding.Enc8Bit);
        else if (settings.getPhoneSettings().getMessageEncoding().equalsIgnoreCase("unicode"))
          message.setMessageEncoding(CMessage.MessageEncoding.EncUcs2);
        else message.setMessageEncoding(CMessage.MessageEncoding.Enc7Bit);
        messageList.add(message);
      }
      rs.close();
      mainThread.service.sendMessage(messageList);
      for (int i = 0; i < messageList.size(); i++) {
        message = (COutgoingMessage) messageList.get(i);
        if (message.getDispatchDate() != null) {
          settings.getGeneralSettings().rawOutLog(message);
          if (mainThread.mainWindow != null) {
            mainThread.mainWindow.setOutTo(message.getRecipient());
            mainThread.mainWindow.setOutDate(message.getDispatchDate().toString());
            mainThread.mainWindow.setOutText(message.getText());
          } else {
            System.out.println(CConstants.TEXT_OUTMSG);
            System.out.println("\t" + CConstants.LABEL_OUTGOING_TO + message.getRecipient());
            System.out.println("\t" + CConstants.LABEL_OUTGOING_DATE + message.getDate());
            System.out.println("\t" + CConstants.LABEL_OUTGOING_TEXT + message.getText());
          }
          sqlCmd2.executeUpdate(
              "update sms_out set dispatch_date = "
                  + escapeDate(message.getDispatchDate(), true)
                  + " where id = "
                  + message.getId());
        }
      }
      sqlCmd2.close();
      connection.commit();
    } else {
      rs.close();
      connection.rollback();
    }
    sqlCmd1.close();
  }
  protected void initIndexes(ConnectionProvider cp, String tbl) {
    if (cp != null)
      try {
        boolean unique;
        DatabaseMetaData dmd = cp.getDatabaseMetaData();
        String shortTableName;
        if (tbl == null) shortTableName = getName().getName();
        else shortTableName = tbl;

        ResultSet rs;
        //                    rs = dmd.getIndexInfo(cp.getConnection().getCatalog(),
        // dmd.getUserName().trim(), shortTableName, false, true);
        rs =
            dmd.getIndexInfo(
                cp.getConnection().getCatalog(), cp.getSchema(), shortTableName, false, true);

        String name, columnName;
        boolean unq;
        LinkedList idxs = new LinkedList();
        if (rs != null) {
          HashMap rset = new HashMap();
          String uniqueStr;
          while (rs.next()) {
            name = rs.getString("INDEX_NAME"); // NOI18N
            columnName = rs.getString("COLUMN_NAME"); // NOI18N
            if (columnName != null) columnName = columnName.trim();
            unq = rs.getBoolean("NON_UNIQUE"); // NOI18N
            // hack for PostgreSQL bug 3480: the driver returns quotes around quoted column names
            if (columnName != null
                && columnName.length() >= 2
                && columnName.startsWith("\"")
                && columnName.endsWith("\"")) { // NOI18N
              columnName = columnName.substring(1, columnName.length() - 1);
            }

            if (name == null) continue;
            else name = name.trim();

            if (unq) idxs.add(name + "." + columnName + ".false"); // NOI18N
            else idxs.add(name + "." + columnName + ".true"); // NOI18N
          }
          rs.close();
        }

        String info;
        int start, end;
        for (int i = 0; i < idxs.size(); i++) {
          info = idxs.get(i).toString();
          start = info.indexOf('.'); // NOI18N
          end = info.lastIndexOf('.'); // NOI18N
          name = info.substring(0, start);
          if ((info.substring(end + 1)).equals("true")) // NOI18N
          unique = true;
          else unique = false;

          if (indexes.find(DBIdentifier.create(name)) != null) continue;

          IndexElementImpl iei = new IndexElementImpl(this, name, unique);
          IndexElement[] ie = {new IndexElement(iei, (TableElement) element)};
          iei.initColumns(idxs);
          changeIndexes(ie, DBElement.Impl.ADD);
        }
      } catch (Exception exc) {
        if (Boolean.getBoolean("netbeans.debug.exceptions")) // NOI18N
        exc.printStackTrace();
      }
  }