Status: Current. Where this is implemented names the code and the tests.
A pull finds objects in the database and brings into a session the objects that its results hold,
with the objects that their includes reach. A result without a select holds the objects that the
pull finds; a result with a select holds only the objects at the end of the select.
session.PullAsync(params Pull[] pulls) sends several pulls together and returns one
IPullResult. Give collections in the same call distinct names. The classes of a pull
are in the namespace Allors.Workspace.Data.
Extents explains the predicates.
Pull gives the form that the Remote adapter sends, and
The workspace explains what a pull brings into a
session. The examples use the sample’s metadata m.
A pull
Section titled “A pull”| Property | Holds |
|---|---|
Extent | An extent: a Filter, a Union, an Intersect or an Except. |
ExtentRef | The id of a prepared extent, instead of Extent. |
Object, ObjectId | An object of the session, or the id of an object, instead of an extent. |
ObjectType | With an object: a class or an interface. The pull finds nothing when the object is not of that type. |
Results | What the pull returns. Leave it null to return the objects that the pull finds. With Array.Empty<Result>(), the Local adapter returns no objects and the Remote adapter returns the matches. See Results. |
Arguments | The values of the parameters of its predicates, by name. |
A pull of a new object of the session, which has a negative id, throws an ArgumentException
with the message Id is not in the database. A pull of an id that does not exist in the database
throws: an HttpRequestException for HTTP 500 on the Remote adapter, and on the Local adapter an
Exception with the message Either an Extent or an ExtentRef is required.
Extents
Section titled “Extents”| Extent | Holds |
|---|---|
new Filter(m.WorkItem) | The objects of a class or an interface that match its Predicate, or all of them without one. |
new Union(first, second) | The objects of either operand. |
new Intersect(first, second) | The objects of both operands. |
new Except(first, second) | The objects of the first operand that are not in the second. |
Each extent has Sorting, a list of Sort objects: new Sort(m.Person.LastName), ascending
unless its SortDirection is Descending. The first sort comes first.
Predicates
Section titled “Predicates”The Predicate of a filter holds one predicate; And, Or and Not combine others. The first
argument of a predicate is a role type or an association type of the extent’s type. Like,
GreaterThan, LessThan and Between take a role type only, and Equals and Instanceof can do
without either.
| Predicate | Takes | An object matches when |
|---|---|---|
Equals | Value, Object or Path | The role has the value or holds the object, the association is the object, or the unit role equals the unit role in Path of the same object. Without a role type or an association type: the object is Object. |
Like | Value | The string role matches the pattern; % stands for any run of characters and _ for one character. |
GreaterThan, LessThan | Value or Path | The role is greater than, or less than, the value or the role in Path. |
Between | Values, two values, or Paths, two role types | The role lies between the two, both included. |
Exists | Nothing | The role holds something, or the association exists. |
Contains | Object | The role or the association, one that holds several objects, holds the object. |
ContainedIn | Extent or Objects | An object of the role or the association is among those of the extent or the list. |
Instanceof | ObjectType | The object in the role or the association is of that class or interface; without a role type or an association type, the object itself is. |
And, Or | Operands | Every operand holds, or one does. |
Not | Operand | The operand does not hold. |
var result = await session.PullAsync(new Pull{ Extent = new Filter(m.Person) { Predicate = new Equals(m.Person.UserName) { Value = "jane@example.com" } },});Equals without a Value, an Object or a Path adds no condition. An And or an Or with
zero operands, or a Not without an operand, also adds no condition. If any of these is the
filter’s only predicate, the filter matches every object of its type. An Instanceof without
ObjectType matches nothing. For Like, GreaterThan, LessThan, Between, Contains and
ContainedIn, omitting the value, object, extent or path that the predicate takes makes the Local
adapter throw an ArgumentException or a NullReferenceException and the Remote adapter throw
an HttpRequestException for HTTP 500.
Filter states the rules of the predicates and of their patterns.
Parameters
Section titled “Parameters”Instead of a value, a predicate can name an argument in Parameter. The pull’s Arguments give
the value by that name, and a predicate whose argument is missing from them is left out.
Dependencies names further arguments; the predicate is left out when one of them is missing. The
adapters differ:
- Local. The arguments apply, in the form that the database takes: an object by its id, a
long, several objects as along[], a class or an interface by its tag, and a unit by its value. To compare the object itself, usenew Equals { Object = person }. With no role type or association type,new Equals { Parameter = "person" }is left out when the id does not resolve; otherwise it compares against its unsetObject, so even a valid id gives no matches on Memory or Snapshot. A pull whoseArgumentsisnullthrows aNullReferenceExceptionfor a predicate with aParameteror withDependencies. - Remote. The .NET adapter does not send
Arguments, so the server leaves out a predicate with aParameteror withDependencies. It omits theParameterof anInstanceofas well. With no explicitObjectTypeor dependencies, that predicate stays and matches nothing. The TypeScript workspace sends the arguments.
Results
Section titled “Results”| Property | Holds |
|---|---|
Name | The name of the result. |
Select | A path along roles and associations, from each object that the pull finds. The result holds the objects at its end. |
SelectRef | The id of a prepared select, instead of Select. |
Include | The objects to bring into the session along the roles and associations of the result’s objects, when the result has no select. |
Skip, Take | Skip some objects of an extent and take some; a pull of an object ignores both. |
Select
Section titled “Select”new Select(m.WorkItem.Assignee) holds the assignee of each work item that the pull finds; the
result holds each object once. new Select(m.WorkItem.Assignee, m.Person.WorkItemsWhereAssignee)
takes two steps, each in a Select of its own, linked through Next; End is the last step.
OfType on a step keeps the objects of one class or interface. The Local adapter ignores it
when the workspace supplies the select in Result.Select.
The position of a step that holds several objects matters when each step finds objects.
- Local. A select can follow a step that holds several objects if its last step holds one
object. If the last step holds several, the Local adapter throws an
Exceptionthat wraps anInvalidCastException, even if an earlier step also holds several. - Remote. A pull of one object can follow a step that holds several objects anywhere in the path. In a pull of an extent, only the last step can hold several. An earlier such step gives HTTP 500. The two-step example above works on the Remote adapter because only its last step holds several.
Include
Section titled “Include”An include is a tree of Node objects. The generated metadata builds one:
var result = await session.PullAsync(new Pull{ Extent = new Filter(m.WorkItem), Results = new[] { new Result { Include = m.WorkItem.Nodes(v => v.Assignee.Node()) } },});Node takes a further step from the type at the end of a role, through ObjectType:
m.WorkItem.Nodes(v => v.Assignee.Node(w => w.ObjectType.WorkItemsWhereAssignee.Node())) brings
the assignee of each work item and the work items of that assignee.
On a result with a select, put the include on the last step, select.End.Include, and leave
earlier steps without one. Both adapters apply the include to the objects at the end of the
select. The Local adapter uses the first step’s Include if set and otherwise uses the last
step’s. The Remote adapter uses only the last step’s. Both ignore Include on the result itself.
A result without a name is named after what it holds:
| Result | Name |
|---|---|
| A pull of an extent | The plural name of the extent’s type, such as WorkItems. |
| A pull of an object | ObjectType, or else the singular name of the object’s class, such as Person. |
| A select | On the Remote adapter, the plural name of the role or the association at its end, such as Assignees, or its singular name on a pull of an object when the select leads to one object. On the Local adapter, a select that ends in a role takes the full name of the role instead, such as WorkItemAssignees or WorkItemAssignee. |
Name every result that has a select. Give collections in the same call distinct names, even across
pulls. For example, two pulls of WorkItem extents both default to WorkItems. If both find
matches and the second collection has no include, both adapters add its ids to the existing
collection but skip loading the additional objects. In a fresh session those entries read as null.
result.GetCollection<WorkItem>() takes the collection with the plural name of the type, and
GetCollection<Person>("Assignees") a collection by name;
GetObject<Person>() and GetObject<Person>(name) do the same for one object, and both return
null when the result has no such name. The Remote adapter ignores the case of a name in these
methods; the Local adapter does not. Collections, Objects and Values hold them all, by name;
on the Remote adapter their names are in upper case, such as WORKITEMS.
Read a value that a procedure returned with GetValue<T>(name) and the type of its unit. The Local
adapter casts the value that the procedure added. The Remote adapter converts the JSON of the
answer, and its GetValue<T> takes the types of the units only.
Paging
Section titled “Paging”Skip and Take apply to the objects of an extent:
- With a select. The Remote adapter pages before the select, so
Take = 1gives the objects that the select reaches from the first object. The Local adapter pages the objects that the select reaches. - Before or after leaving objects out. The Remote adapter pages the objects that it may return.
The Local adapter pages first and then leaves out the objects of a class outside the workspace
and the objects that a mask hides, so it can return fewer than
Take.
Several results
Section titled “Several results”A pull can have several results. In a pull of an extent, each result starts from the objects that the pull finds on the Remote adapter; on the Local adapter, a result after a result with a select starts from the objects of that select. In a pull of an object, a result after a select that leads to one object starts from that object, on both adapters.
Prepared extents and selects
Section titled “Prepared extents and selects”A prepared extent or select is defined on the side of the database, in the configuration of the
application, and a pull names it by its id in ExtentRef or SelectRef. The configuration
registers them, by id, in the classes PreparedExtents and PreparedSelects of
Database/Configuration/Custom. The sample registers none.
Procedures
Section titled “Procedures”session.CallAsync(procedure, pulls) runs a procedure of the database and the pulls, in one
request:
var procedure = new Procedure("TestValues");
var result = await session.CallAsync(procedure);
Assert.False(result.HasErrors);Assert.True(result.GetValue<bool>("allorsBoolean"));- The procedure is a class of the domain that implements
IProcedure, with a constructor without parameters. The database finds it by the name of its class, ignoring case. ItsExecutetakes a context, with the transaction and the access control of the pull, the input and the output. - The input.
ProceduretakesCollections,ObjectsandValuesby name, andPool, the objects whose versions the database checks first. A version that has changed is a version error, and the procedure does not run. - The output. The procedure adds collections, objects and values by name; the pull result holds them. A procedure runs in the transaction of the pull, which the platform does not commit, so what the procedure changes is not stored unless the procedure commits it.
- A missing procedure gives
Missing procedure <name>inErrorMessage. - When the procedure fails, with a version error, a missing procedure or an error that it
adds, the adapters differ. The Remote adapter runs none of the pulls, and its result then has no
collections, objects or values:
GetCollectionand the others throw. The Local adapter runs the pulls anyway, and brings their objects into the session.
TestValues is a procedure of Core’s test domain; the sample has none.
Custom routes
Section titled “Custom routes”session.CallAsync(args, name) sends args as JSON to the custom route <name>/pull, relative to
the base address of the Remote adapter, and reads the answer as the answer of a pull. The
application’s server answers with a controller of its own: the server’s route
allors/{controller}/{action} sends People/pull to the action Pull of a PeopleController,
which builds the answer with Core’s Api.CreatePullResponseBuilder(). The code marks that method
for deletion, and its builder adds no dependencies. A name without a controller gets HTTP 404,
which throws an HttpRequestException. Core’s test server has such controllers in
dotnet/Core/Database/Server/Custom; the sample’s server has none.
The Local adapter has no custom routes: CallAsync(args, name) throws a
NotImplementedException.
Where the adapters differ
Section titled “Where the adapters differ”The Local adapter runs a pull in the process, and the Remote adapter sends it to the server. Most pulls give the same objects on both, apart from these:
| Pull | Local | Remote |
|---|---|---|
Results = Array.Empty<Result>() | Returns no objects | Returns the matches |
The name of a result whose select ends in a role, without Name | The full name of the role, such as WorkItemAssignees | The name of the role, such as Assignees |
The case of a name in GetCollection and GetObject | Must match | Ignored |
The names in Collections, Objects and Values | As the result names them | In upper case |
GetValue | The value that the procedure added | The JSON of the answer; GetValue<T> takes the types of the units only |
Skip and Take with a select | Applied to the selected objects | Applied before the select |
Skip and Take and the objects that are left out | Applied before objects are left out | Applied to the objects that may be returned |
| In a pull of an extent, a result after a result with a select | Starts from the objects of that select | Starts from the objects of the extent |
OfType on a step in Result.Select | Ignored | Applied |
| A select that reaches a last step holding several objects | Throws an Exception that wraps an InvalidCastException | Returns the objects. In a pull of an extent, an earlier step that also holds several gives HTTP 500. |
| An extent with a select whose earlier step holds several objects and whose last step reaches one object per path | Returns the objects | HttpRequestException, HTTP 500 |
| An include on the first step of a select with several steps | Used in preference to the last step’s include | Ignored |
Parameter and Dependencies | Apply with the exception for object equality. A null arguments dictionary throws. | The server leaves the predicate out when an argument is missing. For Instanceof the adapter omits Parameter itself. See Parameters. |
| A procedure that fails | The pulls run | The pulls do not run, and the result has no collections, objects or values |
| An id that does not exist | Exception | HttpRequestException, HTTP 500 |
| A pull to a custom route | NotImplementedException | Sent to the server |
Where this is implemented
Section titled “Where this is implemented”Pull,Result,Select,Node, the extents, the predicates,SortandProcedureare indotnet/System/Workspace/Allors.Workspace.Domain/Data, with the builders of an include inData/Extensions.- The Remote adapter turns a pull into JSON in
dotnet/System/Workspace/Allors.Workspace.Protocol.Json/Data/ToJsonVisitor.cs;VisitPullcopies no arguments. The server answers indotnet/System/Database/Allors.Database.Workspace.Json/Pull. - The Local adapter turns a pull into the database’s in
dotnet/System/Workspace/Allors.Workspace.Protocol.Direct/ToDatabaseVisitor.cs, which copies noOfType, with its arguments inArguments.csnext to it, and runs it indotnet/System/Workspace/Adapters/Allors.Workspace.Adapters.Local/Database/Pull:PullExtent,PullInstantiateandProcedure. - The predicates of
dotnet/System/Database/Allors.Database/Dataleave out a predicate whose argument is missing.SelectExtension.cs, indotnet/System/Database/Allors.Database.Workspace/Data, takes the steps of a select. IProcedureis indotnet/System/Database/Allors.Database.Workspace/Procedure, andProcedures, which finds a procedure by name, indotnet/Core/Database/Configuration/Core/Database/Procedures.PullTestsandProcedureTests, indotnet/Core/Workspace/Tests/Tests, check the predicates, the operators, the sorting, a named result, an include on a select without a role type (PullWithInclude) and the procedures on each adapter;PagingTestschecksTake, and the sample’sWorkItemTestsan include on a result. No test of the .NET workspace has a select with a step, a parameter or a custom route.