Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit Relation contract. Implements #457 #524

Merged
merged 2 commits into from
Dec 4, 2017

Conversation

dmfs
Copy link
Owner

@dmfs dmfs commented Nov 30, 2017

  • remove all the public static final modifiers
  • remove RELATED_URL
  • remove some currently unsupported RelTypes
  • convert RelTypes from enum to ints to allow unsupported reltypes.

@dmfs dmfs requested a review from lemonboston November 30, 2017 15:16
@dmfs
Copy link
Owner Author

dmfs commented Nov 30, 2017

@lemonboston I want to handle the "reverse relation" issue in a separate story

* When writing a relation, exactly one of {@link #RELATED_ID}, {@link #RELATED_UID} or {@link #RELATED_URI} must be given. {@link #RELATED_CONTENT_URI}
* will be populated automatically if possible.
* </p>
* When writing a relation, exactly one of {@link #RELATED_ID} or {@link #RELATED_UID}. {@link #RELATED_CONTENT_URI} will be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is missing at the end of the first sentence here?

@@ -37,23 +36,23 @@
public final class RelationData extends DelegatingRowData<TaskContract.Properties>
{
public RelationData(@NonNull RowSnapshot<TaskContract.Tasks> relatingTask,
@NonNull RelType relType,
@NonNull int relType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primitive int as @NonNull here, should be Integer, I suppose.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the @NonNull should be removed. I'll take care of that.


if (id == null && uri == null && uid != null)
if (id == null && uid != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this validate() method just simply throw if none or both of RELATED_ID and RELATED_UID are present?
Isn't the value already null when values.putNull(Relation.RELATED_ID); is called?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would only be the case for new rows. When you override a row we need to reset the other value explicitly. That being said, I already considered making rows write-once. So you can only create and delete them. Updates would throw an exception. I'm starting to get used to this idea and it would certainly make a couple of things much simpler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get this - so just by looking at this code:

Long id = values.getAsLong(Relation.RELATED_ID);
String uid = values.getAsString(Relation.RELATED_UID);

if (id == null && uid != null)
{
    values.putNull(Relation.RELATED_ID);
}

and just ignore the 'uid' for a second and inline the 'id' variable, it becomes this:

if (values.getAsLong(Relation.RELATED_ID) == null)
{
    values.putNull(Relation.RELATED_ID);
}

So if the value is null we set it to null.. Or do I miss something?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAsLong also returns null if the value is absent (i.e. not not present in the ContentValues), so we need to explicitly put a null value to ensure we override the old value, otherwise it would remain unchanged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see, thanks

* remove all the `public static final` modifiers
* remove RELATED_URL
* remove some currently unsupported RelTypes
* convert RelTypes from enum to ints to allow unsupported reltypes.
@dmfs dmfs force-pushed the stories/457-relations-update branch from bb539bb to 4d55666 Compare December 1, 2017 22:43
@dmfs
Copy link
Owner Author

dmfs commented Dec 1, 2017

@lemonboston ready for re-review.

@dmfs dmfs force-pushed the stories/457-relations-update branch from 4d55666 to 42b3f80 Compare December 1, 2017 22:45
Copy link
Contributor

@lemonboston lemonboston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@dmfs dmfs merged commit e4538e5 into master Dec 4, 2017
@dmfs dmfs deleted the stories/457-relations-update branch December 4, 2017 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants