Exemplo n.º 1
0
 public void open() throws Exception {
   Class.forName(settings.getDatabaseSettings().getDriver());
   connection =
       DriverManager.getConnection(
           settings.getDatabaseSettings().getUrl(),
           settings.getDatabaseSettings().getUsername(),
           settings.getDatabaseSettings().getPassword());
   connection.setAutoCommit(false);
 }
Exemplo n.º 2
0
  protected String escapeDate(java.util.Date date, boolean includeTime) {
    String dateStr = "";
    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);
    switch (settings.getDatabaseSettings().getType()) {
      case CSettings.CDatabaseSettings.DB_TYPE_SQL92:
        if (includeTime) dateStr = "{ts ?";
        else dateStr = "{d ?";
        dateStr += "" + calendar.get(Calendar.YEAR);
        dateStr += "-";
        dateStr += "" + (calendar.get(Calendar.MONTH) + 1);
        dateStr += "-";
        dateStr += "" + calendar.get(Calendar.DAY_OF_MONTH);
        if (includeTime) {
        } else dateStr += "?}";
        break;
      case CSettings.CDatabaseSettings.DB_TYPE_MSSQL:
        dateStr = "'";
        dateStr += calendar.get(Calendar.YEAR) + "-";
        dateStr += (calendar.get(Calendar.MONTH) + 1) + "-";
        dateStr += calendar.get(Calendar.DAY_OF_MONTH);
        if (includeTime) {
          dateStr += " ";
          dateStr += calendar.get(Calendar.HOUR_OF_DAY) + ":";
          dateStr += calendar.get(Calendar.MINUTE) + ":";
          dateStr += calendar.get(Calendar.SECOND);
          dateStr += "'";
        } else dateStr += "'";
        break;
      case CSettings.CDatabaseSettings.DB_TYPE_MYSQL:
        dateStr = "'";
        dateStr +=
            calendar.get(Calendar.YEAR)
                + "-"
                + (calendar.get(Calendar.MONTH) + 1)
                + "-"
                + calendar.get(Calendar.DAY_OF_MONTH);
        if (includeTime)
          dateStr +=
              " "
                  + calendar.get(Calendar.HOUR_OF_DAY)
                  + ":"
                  + calendar.get(Calendar.MINUTE)
                  + ":"
                  + calendar.get(Calendar.SECOND);
        dateStr += "'";
        break;
    }
    return dateStr;
  }
Exemplo n.º 3
0
 public boolean isOpen() throws Exception {
   if (!settings.getDatabaseSettings().getEnabled()) return false;
   if ((connection == null) || connection.isClosed()) open();
   return (connection != null ? !connection.isClosed() : false);
 }
Exemplo n.º 4
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();
  }