|
You can restrict authority, and make a resource easier to use, by creating a new resource where the
parameters are already bound to values.
A
<http://waterken.com/sql/binding/Statement>
wraps an existing SQL resource and bound parameter values. An SQL binding resource can be used anywhere
that an SQL resource is used. In this section of the tutorial, we will show two examples of using a
binding:
a <Record> that restricts a
<GetCoffee> resource so
that only a particular
<Coffee> can be retrieved;
and a <SetAPrice>
<Lambda> that restricts a
<SetPrice> resource so
that only a particular coffee price can be set.
In a previous tutorial section, we created an SQL query resource that searched
for a <Coffee> by name. To
make a resource that retrieves only a particular
<Coffee>, we can create an
SQL binding resource that reuses the existing SQL query resource and binds the coffee name parameter.
In your xdb folder, open the Colombian coffee binding
<lfd3bkuefm7wpjjz6y4pgy2c3m.xml>.
The base field links to the wrapped
SQL resource, in this case, the coffee search query.
The keys table specifies the bound
arguments. Typically, the bound arguments will be database keys, so the browser resource editor allows
you to specify either an <Integer> or
a <String> value. In this
case, the key is the
<String>
"Colombian".
Click here
to view the representation on your machine.
The <SetAPrice> resource
is much like the previously created
<SetPrice> resource. The
difference is that the
<SetAPrice> resource
binds the coffee name parameter, instead of letting the client specify it.
Open SetAPrice.xml in the schemas folder. Like
<SetPrice>, it contains a
declaration branch. SetAPrice-declaration.xml declares only one parameter: the price, a
<Double>.
The Colombian coffee binding, <7zaaeucdev7fnhb6zovvmnncea.xml>, links to the set
price SQL update resource and binds the coffee name parameter to "Colombian".
The bound arguments contained in an SQL binding resource provide values for the last parameters of an
SQL resource. The last bound argument in the SQL binding resource is the value for the last parameter of
the wrapped SQL resource. The second-to-last bound argument in the SQL binding resource is the value for
the second-to-last parameter of the wrapped SQL resource, and so on.
Click
here to view
the representation on your machine.
Now we have both query and updates resources for a particular coffee. To make these resources easier to
use, we can provide a higher-level resource that aggregates this authority. The
next section describes creating higher-level resources.
|