Ejemplo n.º 1
0
  /**
   * @param from
   * @param to
   * @param body
   * @param direction
   * @throws Exception
   */
  public static List fetchUserMessages(String user, String direction) throws Exception {
    user = prepareName(user);
    IGenericDao dao = null;
    List myList = null;
    try {
      dao = Utility.getDbConnection();
      if (direction.equals(QUEUE_IN)) {
        String sql1 =
            "SELECT * FROM QUEUE WHERE MSG_TO = ? AND MSG_DIRECTION = ? AND DELIVERED = 0 ORDER BY MSG_TIME ASC";
        myList = dao.readList(Queue.class, sql1, new Object[] {user, direction});
      } else {
        String sql2 =
            "SELECT * FROM QUEUE WHERE MSG_FROM = ? AND MSG_DIRECTION = ? AND DELIVERED = 0 ORDER BY MSG_TIME ASC";
        myList = dao.readList(Queue.class, sql2, new Object[] {user, direction});
      }

      if (myList != null) {
        Queue q = null;
        for (int i = 0; i < myList.size(); i++) {
          q = (Queue) myList.get(i);
          setDelivered(q.getId());
        }
      }
    } finally {
      JdbcUtil.close(dao);
      dao = null;
    }
    return myList;
  }
Ejemplo n.º 2
0
  /**
   * Guarda todos los mensajes en la BD
   *
   * @param from
   * @param to
   * @param body
   * @param direction
   * @throws Exception
   */
  public static void push(String from, String to, String body, String direction) {
    IGenericDao dao = null;
    try {
      dao = Utility.getDbConnection();

      Queue q = new Queue();
      q.setDelivered(new Integer(0));
      q.setMsgDirection(direction);
      q.setMsgBody(body);
      q.setMsgFrom(from);
      q.setMsgTime(new Timestamp(new Date().getTime()));
      q.setMsgTo(to);
      System.out.println("USUARIOS Q RECIBEN EL SMS Y SE VAN A INSERTAR EN LA BD ======> " + to);
      // de momento se deja a pelo hasta q este la muc
      q.setType("S");

      log.debug("new message " + direction + " from: " + from + " to: " + to + " body: " + body);

      IObjectMappingKey myObj =
          Utility.persistMan
              .getObjectMappingFactory()
              .createInstance(Queue.class, new AutoGeneratedColumnsMapper(true));
      dao.insert(myObj, q);
    } catch (Exception e) {
      log.error("mesage couldn't be written to db", e);
    } finally {
      try {
        JdbcUtil.close(dao);
      } catch (Exception e) {
        log.fatal("unable to close jdbc connection", e);
      }
      dao = null;
    }
  }
Ejemplo n.º 3
0
  /**
   * @param id
   * @throws Exception
   */
  public static void setDelivered(Long id) throws Exception {
    IGenericDao dao = null;
    try {
      dao = Utility.getDbConnection();

      String sql = "UPDATE QUEUE SET DELIVERED = 1 WHERE ID = ?";
      dao.executeUpdate(sql, new Object[] {id});
    } finally {
      JdbcUtil.close(dao);
      dao = null;
    }
  }
Ejemplo n.º 4
0
 /**
  * @param user
  * @param direction
  * @return
  * @throws Exception
  */
 public static List showAllMessages() throws Exception {
   IGenericDao dao = null;
   List myList = null;
   try {
     dao = Utility.getDbConnection();
     String sql = "SELECT * FROM QUEUE ORDER BY MSG_TIME ASC";
     myList = dao.readList(Queue.class, sql);
   } finally {
     JdbcUtil.close(dao);
     dao = null;
   }
   return myList;
 }