-
Notifications
You must be signed in to change notification settings - Fork 38
Core Annotations
In Frames, a schema is defined by a collection of Java interfaces. The rules that bind the Java interfaces to the underlying graph representation are defined by the following:
- Method name prefixes: get, is, can, set, add, remove
- Annotations: method metadata.
Below specifies that annotations that can be used when defining a Frames interface. By specifying the method argument and return types, the underlying graph is constrained to the interface specification.
annotation | method prefix | arguments | description | example |
---|---|---|---|---|
@Property |
get ,is ,can |
value |
get the property value of an element | @Property("name") |
@Property |
set |
value |
set the property value of an element | @Property("name") |
@Property |
remove |
value |
remove the property of an element | @Property("name") |
@Adjacency |
get |
label , direction |
get the vertex or vertices X related to the vertex |
@Adjacency(label="X", direction=Direction.OUT) |
@Adjacency |
set |
label , direction |
set the vertex or vertices X related to the vertex |
@Adjacency(label="X", direction=Direction.OUT) |
@Adjacency |
add |
label , direction |
add a vertex X related to the vertex and return the vertex X
|
@Adjacency(label="X", direction=Direction.OUT) |
@Adjacency |
remove |
label , direction |
remove a vertex X related to the vertex |
@Adjacency(label="X", direction=Direction.OUT) |
@Incidence |
get |
label , direction |
get the edges X related to the vertex |
@Incidence(label="X", direction=Direction.OUT) |
@Incidence |
add |
label , direction |
add an edge X related to the vertex and return the edge X
|
@Incidence(label="X", direction=Direction.OUT) |
@Incidence |
remove |
label , direction |
remove an edge X related to the vertex |
@Incidence(label="X", direction=Direction.OUT) |
@Domain |
get |
none | get the domain of the adjacency (i.e the source) | @Domain |
@Range |
get |
none | get the range of the adjacency (i.e. the target) | @Range |
Note that “get” and “set” methods for @Adjacency
can be either single-valued or Iterable-valued. For example:
public interface Person {
@Adjacency(label = "spouse")
Person getSpouse();
@Adjacency(label = "spouse")
void setSpouse(Person spouse);
@Adjacency(label = "child")
Iterable<Person> getChildren();
@Adjacency(label = "child")
void setChildren(Iterable<Person> children);
}
The above interface uses both styles of getter and setter: an Iterable-valued style which allows you to set multiple values simultaneously, and gives you back all values at once, and a “functional” style which requires you to specify exactly one value (which can be null), and gives you back at most one value. Each style has its advantages, depending on your application.
“add” methods for @Adjacency
can be either single-valued or no-valued For example:
public interface Person {
@Adjacency(label = "friend")
Person addFriend(); //Returns a new vertex of type friend
@Adjacency(label = "friend")
Person addFriend(Person friend); //Add an existing person as a friend
}