Integrating legacy databases Hence, another join condition is (Web hosting company)

Integrating legacy databases Hence, another join condition is appended: i.ITEM_ID = b.ITEM_ID. You can expand this and add more join conditions if you need additional restrictions. Note that an outer join is generated because the item in question may not have a successful bid, so NULL is returned for each b.* column. You can now call anItem.getSuccessfulBid() to get a reference to the successful bid (or null if none exists). Finally, with or without database constraints, you can t just implement an item.setSuccessfulBid() method that only sets the value on a private field in the Item instance. You have to implement a small procedure in this setter method that takes care of this special relationship and the flag property on the bids: public class Item { … private Bid successfulBid; private Set bids = new HashSet(); public Bid getSuccessfulBid() { return successfulBid; } public void setSuccessfulBid(Bid successfulBid) { if (successfulBid != null) { for (Bid bid : bids) bid.setSuccessful(false); successfulBid.setSuccessful(true); this.successfulBid = successfulBid; } } } When setSuccessfulBid() is called, you set all bids to not successful. Doing so may trigger the loading of the collection a price you have to pay with this strategy. Then, the new successful bid is marked and set as an instance variable. Setting the flag updates the SUCCESSFUL column in the BID table when you save the objects. To complete this (and to fix the legacy schema), your database-level constraints need to do the same as this method. (We ll come back to constraints later in this chapter.) One of the things to remember about this literal join condition mapping is that it can be applied in many other situations, not only for successful or default relationships. Whenever you need some arbitrary join condition appended to your queries, a formula is the right choice. For example, you could use it in a
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.