package com.rd.testproject.model.db.dao;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.rd.testproject.model.db.data.User;

import java.util.ArrayList;
import java.util.List;

import io.realm.Realm;
import io.realm.RealmResults;

public class ContactDao {

    public void saveUser(@NonNull final Realm realm, @NonNull final User user) {
        realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm bgRealm) {
                realm.copyToRealmOrUpdate(user);
            }
        });
    }

    public void saveUser(@NonNull final Realm realm, @NonNull final User user, @NonNull Realm.Transaction.Callback callback) {
        realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm bgRealm) {
                realm.copyToRealmOrUpdate(user);
            }

        }, callback);
    }

    public void saveUserList(@NonNull final Realm realm, @NonNull final List<User> userList) {
        realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm bgRealm) {
                realm.copyToRealmOrUpdate(userList);
            }

        });
    }

    public void saveUserList(@NonNull final Realm realm, @NonNull final List<User> userList, @NonNull Realm.Transaction.Callback callback) {
        realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm bgRealm) {
                realm.copyToRealmOrUpdate(userList);
            }

        }, callback);
    }

    @Nullable
    public User loadUser(@NonNull Realm realm, long id) {
        return realm.where(User.class).equalTo("id", id).findFirst();
    }

    @NonNull
    public List<User> loadUserList(@NonNull Realm realm) {
        List<User> userList = new ArrayList<>();
        userList.addAll(realm.where(User.class).findAll());
        return userList;
    }

    public RealmResults<User> loadUserListAsync(@NonNull Realm realm) {
        return realm.where(User.class).findAllAsync();
    }
}

@@ -1,2130 +1,1903 @@
-package com.rd.testproject.model.db.dao;%0A%0Aimport android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0A%0Aimport com.rd.testproject.model.db.data.User;%0A%0Aim
+**Realm database**%0A%0ARealm Java enables you to efficiently write your app%E2%80%99s model layer in a safe, persisted and fast way. %0A%0A**Prerequisites**%0A%0A 1. Realm do not sup
 port 
-java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport io.realm.Realm;%0Aimport io.realm.RealmResults;%0A%0Apublic class ContactDao %7B%0A%0A    public void saveUser(@NonNull final Realm realm, @NonNull final User user) %7B%0A        realm.executeTransaction(new Realm.Transaction() %7B%0A            @Override%0A            public void execute(Realm bgRealm) %7B%0A                realm.copyToRealmOrUpdate(user);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    public void saveUser(@NonNull final Realm realm, @NonNull final User user, @NonNull Realm.Transaction.Callback callback) %7B%0A        realm.executeTransaction(new Realm.Transaction() %7B%0A            @Override%0A            public void execute(Realm bgRealm) %7B%0A                realm.copyToRealmOrUpdate(user);%0A            %7D%0A%0A        %7D, callback);%0A    %7D%0A%0A    public void saveUserList(@NonNull final Realm realm, @NonNull final List%3CUser%3E userList) %7B%0A        realm.executeTransaction(new Realm.Transaction() %7B%0A            @Override%0A            public void execute(Realm bgRealm) %7B%0A                realm.copyToRealmOrUpdate(userList);%0A            %7D%0A%0A        %7D);%0A    %7D%0A%0A    public void saveUserList(@NonNull final Realm realm, @NonNull final List%3CUser%3E userList, @NonNull Realm.Transaction.Callback callback) %7B%0A        realm.executeTransaction(new Realm.Transaction() %7B%0A            @Override%0A            public void execute(Realm bgRealm) %7B%0A                realm.copyToRealmOrUpdate(userList);%0A            %7D%0A%0A        %7D, callback);%0A    %7D%0A%0A    @Nullable%0A    public User loadUser(@NonNull Realm realm, long id) %7B%0A        return realm.where(User.class).equalTo(%22id%22, id).findFirst();%0A    %7D%0A%0A    @NonNull%0A    public List%3CUser%3E loadUserList(@NonNull Realm realm) %7B%0A        List%3CUser%3E userList = new ArrayList%3C%3E();%0A        userList.addAll(realm.where(User.class).findAll());%0A        return userList;%0A    %7D%0A%0A    public RealmResults%3CUser%3E loadUserListAsync(@NonNull Realm realm) %7B%0A        return realm.where(User.class).findAllAsync();%0A    %7D%0A%7D
+Java outside of Android at the moment.%0A 2. Android Studio %3E= 0.8.6%0A 3. A recent version of the Android SDK.%0A 4. JDK version %3E=7.%0A 5. Support all Android versions since API Level 9 (Android 2.3%0A    Gingerbread & above).%0A%0A**Pros:**%0A%0A - Fast in implementation%0A - Very fast in data loading and saving%0A - Easy to learn and use%0A%0A**Cons:**%0A%0A - In object we can only have:%0A - private instance fields.%0A - default getter and setter methods.%0A - static fields, both public and private.%0A - static methods.%0A - implementing interfaces with no methods.%0A - requires pre-compiled (.so) files integration for all supported%0A   processor models, making app useless in case if new processor%0A   architecture is released and increasing app size by ~2mb per%0A   architecture.%0A - Is still in beta (top version is 0.86.0) and license might be updated%0A   after release (like with genymotion).%0A%0A**Gettings started**%0AAdd compile *'io.realm:realm-android:0.86.0'* to the dependencies of your project%0A%0A**Here how it looks like**%0A%0A%60%60%60java %0Apublic class User extends RealmObject %7B%0A%0A   @PrimaryKey%0A   private long id;%0A   private String firstName;%0A   private String lastName;%0A   private int age;%0A   private RealmList%3CRealmString%3E contactList;%0A%0A   //Generated getters and setters%0A%7D%0A%60%60%60%0A%09%0A%60%60%60java %0A// Get a Realm instance for this thread%0ARealm realm = Realm.getDefaultInstance();%0Arealm.executeTransaction(new Realm.Transaction() %7B%0A            @Override%0A            public void execute(Realm bgRealm) %7B%0A                realm.copyToRealmOrUpdate(obj);%0A            %7D%0A        %7D);%0A%60%60%60%0A%0A%60%60%60java%0A// Load User by id%0Areturn realm.where(Employee.class).equalTo(%22id%22, id).findFirst(); %0A%60%60%60%0A%0A**More info**%0A%0ASee %5BRealm documentation%5D(https://realm.io/docs/java/latest/) for more details
 %0A

Update ContactDao.java