gt:                 user = user + "@" + defaultDomain;
context: package org.claros.chat.controllers;
  
  import java.sql.SQLException;
  import java.sql.Timestamp;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.List;
  
  import org.apache.commons.dbutils.QueryRunner;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.claros.chat.models.Queue;
  import org.claros.chat.utility.Utility;
  import org.claros.commons.db.DbConfigList;
  
  import com.jenkov.mrpersister.impl.mapping.AutoGeneratedColumnsMapper;
  import com.jenkov.mrpersister.itf.IGenericDao;
  import com.jenkov.mrpersister.itf.mapping.IObjectMappingKey;
  import com.jenkov.mrpersister.util.JdbcUtil;
  
  public class QueueController {
      private static Log log = LogFactory.getLog(QueueController.class);
      public static final String QUEUE_IN = "in";
      public static final String QUEUE_OUT = "out";
  
      /**
       *
       * @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.trim());
              q.setMsgFrom(from);
              q.setMsgTime(new Timestamp(new Date().getTime()));
              q.setMsgTo(to);
  
              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;
          }
      }
  
      /**
       *
       * @param from
       * @param to
       * @param body
       * @param direction
       * @throws Exception
       */
      public static List fetchUserMessages(String user, String direction, String defaultDomain) throws Exception {
          user = prepareName(user, defaultDomain);
          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;
      }
  
      /**
       *
       * @param id
       * @throws Exception
       */
      public static void setDelivered(String user, Long id, String defaultDomain) throws Exception {
          user = prepareName(user, defaultDomain);
          IGenericDao dao = null;
          try {
              dao = Utility.getDbConnection();
  
              String sql = "UPDATE QUEUE SET DELIVERED = 1 WHERE MSG_TO = ? AND ID = ?";
              dao.executeUpdate(sql, new Object[] {user, id});
          } finally {
              JdbcUtil.close(dao);
              dao = null;
          }
      }
  
      /**
       *
       * @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;
          }
      }
  
      /**
       *
       * @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;
      }
  
      /**
       *
       *
       */
      public static void clear() {
          QueryRunner run = new QueryRunner(DbConfigList.getDataSourceById("file"));
          try {
              Calendar cal = Calendar.getInstance();
              cal.add(Calendar.MINUTE, -10);
              Timestamp ts = new Timestamp(cal.getTime().getTime());
  
              String sql = "DELETE FROM QUEUE WHERE DELIVERED = 1 AND MSG_TIME < ?";
              run.update(sql, new Object[] {ts});
          } catch (SQLException e) {
  //			log.fatal("unable to clear queue", e);
              log.debug("unable to clear queue" + e.getMessage());
          }
      }
  
      /**
       *
       *
       */
      public static void fullClear() {
          QueryRunner run = new QueryRunner(DbConfigList.getDataSourceById("file"));
          try {
              String sql = "DELETE FROM QUEUE";
              run.update(sql);
          } catch (SQLException e) {
              log.fatal("unable to clear queue", e);
          }
      }
  
      /**
       *
       * @param user
       * @param isGmail
       * @param defaultDomain
       * @return
       */
      public static String prepareName(String user, String defaultDomain) {
          if (user.indexOf("/") > -1) {
              user = user.substring(0, user.indexOf("/"));
          }
  
          if (user.indexOf("@") < 0) {
              if (defaultDomain != null) {
  