Search in sources :

Example 1 with RealmList

use of io.realm.RealmList in project realm-rxjava-example by kboyarshinov.

the class RealmDataService method newIssue.

@Override
public Observable<Issue> newIssue(final String title, final String body, final User user, List<Label> labels) {
    // map internal UI objects to Realm objects
    final RealmUser realmUser = new RealmUser();
    realmUser.setLogin(user.getLogin());
    final RealmList<RealmLabel> realmLabels = new RealmList<>();
    for (Label label : labels) {
        RealmLabel realmLabel = new RealmLabel();
        realmLabel.setName(label.getName());
        realmLabel.setColor(label.getColor());
        realmLabels.add(realmLabel);
    }
    return RealmObservable.object(context, new Func1<Realm, RealmIssue>() {

        @Override
        public RealmIssue call(Realm realm) {
            // internal object instances are not created by realm
            // saving them using copyToRealm returning instance associated with realm
            RealmUser user = realm.copyToRealm(realmUser);
            RealmList<RealmLabel> labels = new RealmList<RealmLabel>();
            for (RealmLabel realmLabel : realmLabels) {
                labels.add(realm.copyToRealm(realmLabel));
            }
            // create RealmIssue instance and save it
            RealmIssue issue = new RealmIssue();
            issue.setTitle(title);
            issue.setBody(body);
            issue.setUser(user);
            issue.setLabels(labels);
            return realm.copyToRealm(issue);
        }
    }).map(new Func1<RealmIssue, Issue>() {

        @Override
        public Issue call(RealmIssue realmIssue) {
            // map to UI object
            return issueFromRealm(realmIssue);
        }
    });
}
Also used : RealmLabel(com.kboyarshinov.realmrxjavaexample.model.RealmLabel) RealmList(io.realm.RealmList) Issue(com.kboyarshinov.realmrxjavaexample.model.Issue) RealmIssue(com.kboyarshinov.realmrxjavaexample.model.RealmIssue) RealmUser(com.kboyarshinov.realmrxjavaexample.model.RealmUser) RealmLabel(com.kboyarshinov.realmrxjavaexample.model.RealmLabel) Label(com.kboyarshinov.realmrxjavaexample.model.Label) RealmIssue(com.kboyarshinov.realmrxjavaexample.model.RealmIssue) Func1(rx.functions.Func1) Realm(io.realm.Realm)

Example 2 with RealmList

use of io.realm.RealmList in project realm-java by realm.

the class RealmListNYTimesMultimediumDeserializer method deserialize.

@Override
public List<NYTimesMultimedium> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    RealmList<NYTimesMultimedium> list = new RealmList<>();
    TreeNode treeNode = jp.getCodec().readTree(jp);
    if (!(treeNode instanceof ArrayNode)) {
        return list;
    }
    ArrayNode arrayNode = (ArrayNode) treeNode;
    for (JsonNode node : arrayNode) {
        NYTimesMultimedium nyTimesMultimedium = objectMapper.treeToValue(node, NYTimesMultimedium.class);
        list.add(nyTimesMultimedium);
    }
    return list;
}
Also used : RealmList(io.realm.RealmList) TreeNode(com.fasterxml.jackson.core.TreeNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) NYTimesMultimedium(io.realm.examples.newsreader.model.entity.NYTimesMultimedium) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with RealmList

use of io.realm.RealmList in project xabber-android by redsolution.

the class XabberAccountManager method saveSyncStatesToRealm.

public void saveSyncStatesToRealm(Map<String, Boolean> syncStateMap) {
    RealmList<SyncStateRealm> realmItems = new RealmList<>();
    for (Map.Entry<String, Boolean> entry : syncStateMap.entrySet()) {
        SyncStateRealm realmItem = new SyncStateRealm();
        realmItem.setJid(entry.getKey());
        realmItem.setSync(entry.getValue());
        realmItems.add(realmItem);
    }
    // TODO: 13.03.18 ANR - WRITE
    final long startTime = System.currentTimeMillis();
    Realm realm = RealmManager.getInstance().getNewRealm();
    realm.beginTransaction();
    List<SyncStateRealm> oldItems = realm.where(SyncStateRealm.class).findAll();
    for (SyncStateRealm item : oldItems) item.deleteFromRealm();
    List<SyncStateRealm> resultRealm = realm.copyToRealmOrUpdate(realmItems);
    realm.commitTransaction();
    realm.close();
    LogManager.d("REALM", Thread.currentThread().getName() + " save sync state: " + (System.currentTimeMillis() - startTime));
    Log.d(LOG_TAG, resultRealm.size() + " syncState items was saved to Realm");
}
Also used : RealmList(io.realm.RealmList) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) HashMap(java.util.HashMap) Map(java.util.Map) EmailRealm(com.xabber.android.data.database.realm.EmailRealm) SyncStateRealm(com.xabber.android.data.database.realm.SyncStateRealm) SocialBindingRealm(com.xabber.android.data.database.realm.SocialBindingRealm) Realm(io.realm.Realm) XabberAccountRealm(com.xabber.android.data.database.realm.XabberAccountRealm) XMPPUserRealm(com.xabber.android.data.database.realm.XMPPUserRealm)

Example 4 with RealmList

use of io.realm.RealmList in project app by TourLive.

the class JudgmentRiderConnectionRepository method getJudgmentRiderConnectionsReturnedByJudgment.

@Override
public RealmList<JudgmentRiderConnection> getJudgmentRiderConnectionsReturnedByJudgment(Judgement judgement) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RealmResults<JudgmentRiderConnection> res = realm.where(JudgmentRiderConnection.class).equalTo("judgements.id", judgement.getId()).findAll();
    RealmList<JudgmentRiderConnection> resList = new RealmList<>();
    resList.addAll(res);
    return resList;
}
Also used : RealmList(io.realm.RealmList) Realm(io.realm.Realm) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)

Example 5 with RealmList

use of io.realm.RealmList in project app by TourLive.

the class MaillotRepository method getAllMaillots.

@Override
public void getAllMaillots(OnGetAllMaillotsCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RealmResults<Maillot> results = realm.where(Maillot.class).findAll();
    RealmList<Maillot> res = new RealmList<>();
    res.addAll(results);
    if (callback != null) {
        callback.onSuccess(res);
    }
}
Also used : RealmList(io.realm.RealmList) Maillot(ch.hsr.sa.radiotour.dataaccess.models.Maillot) Realm(io.realm.Realm)

Aggregations

RealmList (io.realm.RealmList)39 Realm (io.realm.Realm)23 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)17 Test (org.junit.Test)8 RaceGroup (ch.hsr.sa.radiotour.dataaccess.models.RaceGroup)7 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)6 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)6 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)4 Scheduler (io.reactivex.Scheduler)4 DynamicRealm (io.realm.DynamicRealm)4 RealmConfiguration (io.realm.RealmConfiguration)4 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 Maillot (ch.hsr.sa.radiotour.dataaccess.models.Maillot)2 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)2 EmailRealm (com.xabber.android.data.database.realm.EmailRealm)2 SocialBindingRealm (com.xabber.android.data.database.realm.SocialBindingRealm)2 SyncStateRealm (com.xabber.android.data.database.realm.SyncStateRealm)2 XMPPUserRealm (com.xabber.android.data.database.realm.XMPPUserRealm)2 XabberAccountRealm (com.xabber.android.data.database.realm.XabberAccountRealm)2