Realm-java: Support for Google's AutoValue Extensions

Created on 1 Apr 2016  路  8Comments  路  Source: realm/realm-java

Google's AutoValue extensions have reached an RC1 stage.

Realm definitely needs to support this!

Jake Wharton did a talk on AutoValue's extensibility API
http://jakewharton.com/presentation/2016-03-08-ny-android-meetup/

Design-Required T-Feature

Most helpful comment

Honestly,

I don't see why Realm should support AutoValue, because if you are trying to achieve immutable one-way data flow - you are using Realm wrong. It's not what realm is meant for.

@cmelchior feel free to close this on my account.

All 8 comments

The whole inheritance chain seems to be tricky for Realm's annotation processor. @nhachicha #2347 might benefit this I guess?

AutoValue is inherently tricky since it promotes immutable objects and until we can actually provide immutable guarantees ( #1208 ), supporting AutoValue wouldn't make a lot of sense I think.

I think Realm classes would have to be final in the context of the AutoValue Extension API as well which means that we wouldn't be able to play well with the Parcelable extension and we would also have problems with our annotations that are currently limited to fields.

From just looking at the video, I still see some major technical hurdles for supporting AutoValue even with extensions, and it would definitely be something we would have to play around with some more to get any idea about the difficulties involved.

There is a pretty high risk we have to implement most of our annotation processor logic inside the extension, which would be a bit unfortunate.

@FabianTerhorst it seems to open realm instances that are never closed, so I declare it to be not very good.

public void savePersistedState(PersistedState state) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    realm.copyToRealmOrUpdate(state.toRealmObject());
    realm.commitTransaction();
    /// so who closes the Realm? ...oh.
}

@Zhuinden yes, the sample doesn麓t looks good, but the library itself could work.

Is there a timeline when realm will support AutoValue ? Really want this.

Honestly,

I don't see why Realm should support AutoValue, because if you are trying to achieve immutable one-way data flow - you are using Realm wrong. It's not what realm is meant for.

@cmelchior feel free to close this on my account.

As discussed above. We will not add support for AutoValue for standard Realm model classes, but it might come as part of support for projections as described in #5426.

Closing this issue, but follow #5426 for updates.

Was this page helpful?
0 / 5 - 0 ratings