Databases Reference
In-Depth Information
If the target was a DOM-based variable, then the target XPath would be expected
to return a reference to one or more nodes, after which the contents of the source
variable are inserted. In the event that no nodes are returned, as would be the case
if we had no bids recorded against the listing, then a selection exception would
be generated.
However, as the target is an SDO-based variable, the behavior is different. In this
case, the operation will create a new
bidView
element, copy into it the contents of
bidView
, and insert it into the
listingViewEV
variable at the place specified.
Updating a detail SDO
In addition to inserting new bids into our listing, we need to be able to update
existing bids. For example, if the current winning bid is outbid, then we need to
update its status accordingly.
For this scenario, we can use a standard
Copy Operation
to update the status of
the bid within the entity variable. The trick here is to restrict the target of the
Copy
Operation
to the appropriate bid.
The simplest way to achieve this is to create a standard
Copy Operation
, and then
modify the
To XPath
expression to contain a
predicate
to select the required
bid
,
based on its
bidId
. To do this, we would need to create an expression that looks
similar to the following:
/listingViewSDO/BidView[BidId=bpws:getVariableData('bidId')]/
Status
Here,
bidId
is just an integer-based variable containing the ID of the bid that we
want to modify.
Deleting a detail SDO
There may also be scenarios where we need to delete a bid from the entity variable.
In such a case, we can do this using an
Assign
with a
Remove Operation
to remove
the
bidView SDO
from the
listingViewEV
entity variable.
As is the case when updating a detail SDO, we need to modify the XPath predicate to
remove only the required
bidView SDO
.
Deleting a Service Data Object
The
Remove Entity
activity allows us to delete an SDO that is bound to an entity
variable, as well as any detail SDOs that are associated with it, a bit like a cascade
delete within SQL.