Search in sources :

Example 1 with ForumUserBd

use of forpdateam.ru.forpda.data.realm.ForumUserBd in project ForPDA by RadiationX.

the class ForumUsersCache method getUserById.

public static ForumUser getUserById(int id) {
    ForumUser resultUser = null;
    Realm realmInstance = Realm.getDefaultInstance();
    ForumUserBd realmResult = realmInstance.where(ForumUserBd.class).equalTo("id", id).findFirst();
    if (realmResult != null) {
        resultUser = new ForumUser(realmResult);
    }
    realmInstance.close();
    return resultUser;
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) ForumUserBd(forpdateam.ru.forpda.data.realm.ForumUserBd) Realm(io.realm.Realm)

Example 2 with ForumUserBd

use of forpdateam.ru.forpda.data.realm.ForumUserBd in project ForPDA by RadiationX.

the class ForumUsersCache method saveUsers.

public static void saveUsers(List<ForumUser> forumUsers) {
    Realm realmInstance = Realm.getDefaultInstance();
    realmInstance.executeTransaction(realm -> {
        List<ForumUserBd> bdList = new ArrayList<>();
        for (ForumUser item : forumUsers) {
            bdList.add(new ForumUserBd(item));
        }
        realm.insertOrUpdate(bdList);
    });
    realmInstance.close();
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) ForumUserBd(forpdateam.ru.forpda.data.realm.ForumUserBd) ArrayList(java.util.ArrayList) Realm(io.realm.Realm)

Example 3 with ForumUserBd

use of forpdateam.ru.forpda.data.realm.ForumUserBd in project ForPDA by RadiationX.

the class ForumUsersCache method loadUserByNick.

public static ForumUser loadUserByNick(String nick) throws Exception {
    ForumUser resultUser = null;
    Realm realmInstance = Realm.getDefaultInstance();
    ForumUserBd realmResult = realmInstance.where(ForumUserBd.class).equalTo("nick", nick).findFirst();
    if (realmResult != null) {
        resultUser = new ForumUser(realmResult);
    }
    realmInstance.close();
    if (realmResult != null) {
        return resultUser;
    }
    List<ForumUser> loadedForumUsers = Api.Qms().findUser(nick);
    for (ForumUser user : loadedForumUsers) {
        if (nick.equals(user.getNick())) {
            resultUser = user;
            break;
        }
    }
    if (resultUser != null) {
        loadedForumUsers.clear();
        loadedForumUsers.add(resultUser);
        saveUsers(loadedForumUsers);
    }
    return resultUser;
}
Also used : ForumUser(forpdateam.ru.forpda.api.others.user.ForumUser) ForumUserBd(forpdateam.ru.forpda.data.realm.ForumUserBd) Realm(io.realm.Realm)

Aggregations

ForumUser (forpdateam.ru.forpda.api.others.user.ForumUser)3 ForumUserBd (forpdateam.ru.forpda.data.realm.ForumUserBd)3 Realm (io.realm.Realm)3 ArrayList (java.util.ArrayList)1