The difference between a Link and a RecordId is that a Link can be relative. This means that the link needs to be resolved against the context it occurs in (= the record it occurs in) in order to get the actual id of the record it points to.
As an example, suppose we have a record with a variant property 'language=en'. In this record, we want to link to another record, also having the 'language=en'. By using Link, we can specify only the master record ID of the target record, without the 'language=en' property. The 'language=en' will be inherited from the record in which the link occurs. The advantage is that if the link is copied to another record with e.g. 'language=fr', the link will automatically adjust to this context.
Links have the following possibilities to specify the relative link:
If you just want a link to point to an exact record id, use the constructor new Link(recordId, false).
To have a link that copies variant properties from the context, use: new Link(recordId).
In such cases you might want to consider creating the link based only on the master record id new Link(recordId.getMaster()).
The Link class is immutable after construction. You have to either pass all properties through constructor arguments, or use the LinkBuilder class obtained via {@link #newBuilder}.
Example using LinkBuilder:
RecordId recordId = ...; Link link = Link.newBuilder().recordId(recordId).copyAll(false).copy("dev").set("foo", "bar").create();
To resolve a link to a RecordId, using the {@link #resolve(RecordId,IdGenerator)} method.
|
|