Paths
A path is essentially a type-safe list of property
references encapsulated in an object of type gw.api.path.Path. Each element
of the path must have an owning type that is the same type or subtype
of the feature type of the immediately previous element in the path.
In other words, starting at element 2, the left side of the literal must
match the right side of the literal in the previous element in the path.
From a programming perspective, Path is an interface. For use
with the query builder APIs, the only relevant implementing class is
PersistentPath, which
contains only persistent property references.
Making a path
To create a path, use the gw.api.path.Paths class, which
has a static method called make.
Pass each property reference in order as separate ordered method arguments.
The make method has method
signatures that support paths of length 1, 2, 3, 4, and 5. The make method only works with property
references that represent persistent properties. A persistent property is a property that
directly maps to a database field.
The following example creates a path with two property references
var path = Paths.make(User#Contact, UserContact#PrimaryAddress)Appending a path
You can append a property with the append method:
var pathPostalCode = path.append(Address#PostalCode)Converting a path to a list
You can convert a path to an immutable
list that implements java.util.List:
var pathAsList = pathPostalCode.asList()The elements of the list are
Contact, PrimaryAddress, and PostalCode.
Getting the leaf value from a path and an object
Given an object and a path, you can get the leaf value (the final and rightmost property in the path) using the getLeafValue method:
var postalCode = pathPostalCode.getLeafValue(user)You must ensure that no element
in the path to the leaf is null.
An entity query on the User table can use this method
to access the leaf values:
var query = Query.make(User)
var rowResult = query.select()
for (user in rowResult){
print(user.DisplayName + " " +
(user.Contact.PrimaryAddress == null ? "No address" : pathPostalCode.getLeafValue(user)))
}