public void updateOnlineStatus(final String userId,final String ip,final boolean onlineFlag) throws ServiceException {
  Transaction transaction=null;
  try {
    final JSONObject user=userRepository.get(userId);
    if (null == user) {
      return;
    }
    user.put(UserExt.USER_COUNTRY,"中国");
    user.put(UserExt.USER_PROVINCE,"云南");
    user.put(UserExt.USER_CITY,"昆明");
    transaction=userRepository.beginTransaction();
    user.put(UserExt.USER_ONLINE_FLAG,onlineFlag);
    user.put(UserExt.USER_LATEST_LOGIN_TIME,System.currentTimeMillis());
    if (onlineFlag) {
      user.put(UserExt.USER_LATEST_LOGIN_IP,ip);
    }
    userRepository.update(userId,user);
    transaction.commit();
  }
 catch (  final RepositoryException e) {
    LOGGER.log(Level.ERROR,"Updates user online status failed",e);
    if (null != transaction && transaction.isActive()) {
      transaction.rollback();
    }
    throw new ServiceException(e);
  }
}

public void updateOnlineStatus ( final String userId , final String ip , final boolean onlineFlag ) throws ServiceException { Transaction transaction = null ; try { final JSONObject user = userRepository . get ( userId ) ; if ( null == user ) { return ; } user . put ( UserExt . USER_COUNTRY , "中国" ) ; user . put ( UserExt . USER_PROVINCE , "云南" ) ; user . put ( UserExt . USER_CITY , "昆明" ) ; transaction = userRepository . beginTransaction ( ) ; user . put ( UserExt . USER_ONLINE_FLAG , onlineFlag ) ; user . put ( UserExt . USER_LATEST_LOGIN_TIME , System . currentTimeMillis ( ) ) ; if ( onlineFlag ) { user . put ( UserExt . USER_LATEST_LOGIN_IP , ip ) ; } userRepository . update ( userId , user ) ; transaction . commit ( ) ; } catch ( final RepositoryException e ) { LOGGER . log ( Level . ERROR , "Updates user online status failed" , e ) ; if ( null != transaction && transaction . isActive ( ) ) { transaction . rollback ( ) ; } throw new ServiceException ( e ) ; } }
updates a user ' s online status and saves the login time and ip .
