コード例 #1
0
ファイル: CDatabase.java プロジェクト: tdms/CS6240
  public void saveSentMessage(COutgoingMessage message) throws Exception {
    Statement sqlCmd;

    if (connection != null) {
      sqlCmd =
          connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      sqlCmd.executeUpdate(
          "insert into sms_out (recipient, text, dispatch_date, flash_sms, status_report, src_port, dst_port, validity_period) values ('"
              + message.getRecipient()
              + "', '"
              + message.getText().replaceAll("'", "''")
              + "', "
              + escapeDate(message.getDate(), true)
              + ", "
              + (message.getFlashSms() ? 1 : 0)
              + ", "
              + (message.getStatusReport() ? 1 : 0)
              + ", "
              + message.getSourcePort()
              + ", "
              + message.getDestinationPort()
              + ", "
              + message.getValidityPeriod()
              + ")");
      connection.commit();
      sqlCmd.close();
    }
  }
コード例 #2
0
ファイル: CDatabase.java プロジェクト: tdms/CS6240
  public void saveMessage(CIncomingMessage message) throws Exception {
    Statement sqlCmd;

    sqlCmd =
        connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    switch (message.getType()) {
      case CIncomingMessage.MessageType.Incoming:
        sqlCmd.executeUpdate(
            "insert into sms_in (type, originator, message_date, text) values ('I', '"
                + message.getOriginator()
                + "', "
                + escapeDate(message.getDate(), true)
                + ", '"
                + message.getText().replaceAll("'", "''")
                + "')");
        break;
      case CIncomingMessage.MessageType.StatusReport:
        CStatusReportMessage msg = (CStatusReportMessage) message;
        sqlCmd.executeUpdate(
            "insert into sms_in (type, originator, message_date, text, ref_no, original_sent_date, date_received) values ('T', '"
                + msg.getOriginator()
                + "', "
                + escapeDate(new java.util.Date(), true)
                + ", '"
                + msg.getText().replaceAll("'", "''")
                + "', "
                + msg.getRefNo()
                + ", "
                + escapeDate(msg.getDateOriginal(), true)
                + ", "
                + escapeDate(msg.getDateReceived(), true)
                + ")");
        break;
    }
    connection.commit();
    sqlCmd.close();
  }
コード例 #3
0
ファイル: CDatabase.java プロジェクト: tdms/CS6240
  // @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();
  }