realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Realm Auto Update

Open AnirudhLoya opened this issue 11 years ago • 5 comments

Using PrimaryKey,and RealmAdapter

createOrUpdateAllFromJson() ,Is working Fine with Changes in data,and inserting new data,

when i removed some data from response ,at that the createOrUpdateAllFromJson(),it is not removing the data,which i deleted recently.it is showing entire data.

for example: first response have 5 rows it is saved sucessfully second time i removed 2 rows,now we have 3 rows but it is showing 5 rows.

AnirudhLoya avatar Jun 22 '15 15:06 AnirudhLoya

Can you please share some codes about how do you remove rows from realm?

beeender avatar Jun 23 '15 04:06 beeender

i am not removing rows from realm,this is my case in example json,file that is cities.json i saved data in realm i put sucessfull using createOrUpdateAllFromJson(), for the next i removed some objects from cities.json,again i did the same thing but the rows i removed in the cities.json is not deleted, form the database,database is not updated in this case.

i used city.Classs

public class City extends RealmObject { @PrimaryKey private long votes; private String name;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public long getVotes() {
    return votes;
}

public void setVotes(long votes) {
    this.votes = votes;
}

}

i am using Votes As primary key

the data is updating and created is sucessfully, deletion of some ids is not updating the database..

AnirudhLoya avatar Jun 23 '15 05:06 AnirudhLoya

Sorry, i asked a wrong question. I mean how did you delete the data from the Realm? Here is the doc about the deletion: https://realm.io/docs/java/latest/#deletion

And more, usually you have to build a query, get the query results and delete Objects from there like:

realm.beginTransaction();
realm.where(Dog.class).equalTo("id", idToDelete).findAll().clear();
realm.commitTransaction()

I guess your case is like you want to import from a json file to a fresh new Realm every time. Maybe you can try something like:

realm.beginTransaction()
realm.allObjectes(YourModel.class).clear();
realm.createAllFromJson(YourModel.class, jsonInputStream);
realm.commitTransaction()

For the on-disk realm, the data you wrote to it, will be stored on the disk until you delete the Realm file or remove the data.

beeender avatar Jun 23 '15 06:06 beeender

Thanks for u r Quick Reply, i already used this but i want to know if Update will do this, or not

Now my doubt,is clear Thank u.

If their is chance think about This case,which will help to maintain the data in the table based on the response,and refresh the ui. no need to clear the table every time,may be usefull in most cases, withlow effort we can main update database..

RealTime updatation of database,accoeding to present server response..

AnirudhLoya avatar Jun 23 '15 06:06 AnirudhLoya

Thanks a lot for your feedback!

Well, currently calling clear is relatively not a big effort :stuck_out_tongue: We'd like to keep the API simpler :smile:

I am closing this issue right now. If you need any other thing about Realm needs to be supported, stackoverflow might be a better place!

beeender avatar Jun 23 '15 09:06 beeender