@Override // public synchronized void update(String userAccount, XMPPUser contact) { public void update(String userAccount, XMPPUser contact) { db = getTransactionDB(); synchronized (synchObj) { // 是否存在 DBUser user = userDao.findByAccount(userAccount); if (user == null) { return; } DBUser ct = userDao.findByName(contact.getJid()); if (ct == null) { add(userAccount, contact); return; } // 查找group,不存在会创建新的分组 String group = contact.getGroup(); DBFriendGroup fg = fgDao.find(userAccount, group); DBFriendGroupMapping mp = new DBFriendGroupMapping(); mp.setUser(ct); mp.setFriendGroup(fg); mp.setLoginState(contact.getStatusMode()); mp.setRemark(contact.getNickname()); // 查找mapping中是否存在 DBFriendGroupMapping mapping = find(userAccount, ct.getAccount()); if (mapping != null) { // 更新 mp.setAccount(mapping.getAccount()); update(mp); } else { // 不存在,添加 String acc = Integer.parseInt(getMaxAccount()) + 1 + ""; mp.setAccount(acc); add(mp); } } }
@Override // public synchronized void add(String account, XMPPUser contact) { public void add(String account, XMPPUser contact) { db = getTransactionDB(); synchronized (synchObj) { // 查找group String group = contact.getGroup(); DBFriendGroup fg = fgDao.find(account, group); // 查找contact String jid = contact.getJid(); DBUser ct = userDao.findByName(jid); if (ct == null) { // 添加contact // 查找account String ua = userDao.findMaxAccount(); ua = Integer.parseInt(ua) + 1 + ""; ct = new DBUser(); ct.setAccount(ua); ct.setNickname(jid); // ct.setState(contact.getStatusMode()); ct.setDesp(contact.getStatusMessage()); ct.setRegisterTime(new Date().getTime()); userDao.add(ct); } // 是否已经存在,add(mapping)中会检查 // 添加mapping DBFriendGroupMapping mapping = new DBFriendGroupMapping(); mapping.setFriendGroup(fg); mapping.setUser(ct); mapping.setRemark(contact.getNickname()); mapping.setLoginState(contact.getStatusMode()); String ac = Integer.parseInt(getMaxAccount()) + 1 + ""; mapping.setAccount(ac); add(mapping); } }