Databases Reference
In-Depth Information
thereisnocasewhere{
anotherBidisaTBidand
anotherBid.status=="NEW"&&
Duration.compare(anotherBid.bidtime,nextBid.bidtime)<0
}
and
auctionItemisaTAuctionItemand
nextBid.maxAmount>=auctionItem.startingPrice
and
winningBidisaTBidand
winningBid.status=="WINNING"&&
nextBid.maxAmount>=winningBid.bidAmount+
getBidIncrement(winningBid.bidAmount)&&
nextBid.maxAmount>winningBid.maxAmount
We would then need to reimplement most of this logic for the other two scenarios.
Better practice is to use inference, that is, if A implies B, and B implies C, then we
can infer from this that A implies C. In other words, we don't have to write all of this
within a single rule; the rule engine will automatically infer this for us.
In our scenario, this means that writing a rule to get the next bid (as covered), and
writing two rules to validate any bid with a status of NEXT . These rules will retract
any invalid bids and update their status to reflect this. Finally, we need to write three
rules, one for each of the scenarios identified previously to process each valid bid.
The only thing we need to take into account is that the validation rules must have
a higher priority than the rules which process the next bid, so that they retract any
invalid bids before they can be processed.
Processing the next valid bid
Using inference, we can now write our rules to process the next bid, on the basis that
we already know which bid is next and that the bid is valid. Using this approach,
the rule condition for the first scenario, where the next bid is higher than the current
winning bid, would be specified as shown in the following code snippet:
nextBidisaTBidand
nextBid.status=="NEXT"
and
winningBidisaTBidand
winningBid.status=="WINNING"&&
winningBid.maxAmount<nextBid.maxAmount
This, as we can see, is considerably simpler than the previous example.
 
Search WWH ::




Custom Search