神刀安全网

Realm Java 0.90 — Better Date and API Cleanup!

We just released a new version ofRealm Java to this website and toBintray. This release adds full support for the Date datatype as well as an API cleanup.

Better Date support

Realm Java has from the begining supported the standard java.util.Date , with one limitation. We truncated all timestamps to the nearest second.

The reason was that we wanted all of our products to be compatible, even though their date formats differ widely.

Starting with Realm Java 0.90 and Realm Objective-C & Swift 0.101, we have fixed these issues and Realm Java now supports the full millisecond precision that is normally offered by the Date class.

This change will require an upgrade of the format of the Realm file, but it will happen automatically when opening a Realm file using 0.90+. Enjoy all those milliseconds 😀

Android Adapters

We have decided to split off all Android-specific components into their own repository. This will make it easier to release enhancements and hotfixes for those as well as keeping the general size of the main library down.

This means that from 0.90, the class RealmBaseAdapter is no longer part of the main Realm library, and you will have to add the following depency to get it:

dependencies {  compile 'io.realm:android-adapters:1.0.0' }

Going forward we are planning to add more Android framework support like RecyclerView and Cursors, but if you have any other ideas or feedback, please create an issue in the new Realm Android Adapters repository.

API Cleanup

Realm Java has been in beta for roughly 1.5 years, and during that time we have gotten a lot of feedback and input on how the API should look. For that reason we are now taking the opportunity to do a general cleanup. We are removing things that are not really used and improving others.

The most important items are below:

  • All Realm classes are now final .

  • RealmChangeListener s now send the changed object as a parameter to onChange() .

realm.addChangeListener(new RealmChangeListener<Realm>() {  @Override  public void onChange(Realm realm) {   // A reference to Realm. Note that all Realm instances and objects   // are live objects, so this is just convience and it cannot   // be compared to previous references as they will all be the same.     } });  Person p = realm.where(Person.class).findFirst(); p.addChangeListener(new RealmChangeListener<Person>() {  @Override  public void onChange(Person person) {   person.getName(); // The updated person.  } });

  • All query methods on Realm and DynamicRealm have been deprecated. All query methods should be done through Realm.where() , DynamicRealm.where() or RealmCollection.where() .

  • RealmConfiguration.Builder.setModules() has been renamed to RealmConfiguration.Builder.modules() .

  • Realm.refresh() has been deprecated in favour of Realm.waitForChange() . See this gist for an example of how to use it. This change was motivated by that fact that one-time tasks should either use the asynchronous API’s or open a Realm instance and close it again when done with it. waitForChange is more suited for use-cases where you can’t use the async API (because it requires a Looper thread).

calling waitForChange will block the current Thread until a commit happens in the background or you call stopWaitForChange , which will stop the wait of the Thread that called waitForChange .

See the full changelog for all the details.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on Stack Overflow , GitHub , and Twitter .

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Realm Java 0.90 — Better Date and API Cleanup!

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址