The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Aliasing

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Aliasing Posted: Feb 4, 2004 12:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Aliasing
Feed Title: Avi Bryant
Feed URL: http://smallthought.com/avi/?feed=rss2
Feed Description: HREF Considered Harmful
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Avi Bryant

Advertisement
Since Alan keeps talking about GLORP, I'm gonna talk about ROE...

I've been recently trying a new approach to ambiguous attribute references. Say you have two tables, Professor and Course, and they both a column called 'name'. You want to find the names of any courses taught by a professor named 'Bryant'. In SQL, the query would look like this:


SELECT Course.name FROM Course, Professor WHERE Course.profID = Professor.id AND Professor.name = 'Bryant'

In earlier versions of Roe, however, there was no way to do a Table.column reference, so you had to use aliasing instead. You would first get versions of the professor and course relations with more specific attribute names:

profAlias := professors rename: #name to: #profName.

courseAlias := courses rename: #name to: #courseName.

Then you could do the join/select/project:

names := (profAlias * courseAlias select: [:ea | (ea profName = 'Bryant') & ((ea profID = ea id)]) project: #courseName .

Now, anywhere that an attribute name was previously accepted, you can also use an attribute object. So, the above example could look instead like this:

profName := professors attributeNamed: #name.

courseName := courses attributeNamed: #name.

names := (professors * courses select: [:ea | ((ea at: profName) = 'Bryant') & ((ea profID = ea id))]) project: courseName.

Not a huge deal, maybe, but I always prefer to compare object identity where possible instead of symbols. Another nice example of this is in self joins, where you "alias" a relation by cloning it and assigning it to a different variable. Note also the sugar #>> for #attributeNamed: .

"find all customers with the same last name"

customerAlias := customers clone.

^ (customers * customerAlias select: [:ea | (ea at: customers>>#name) = (ea at: customerAlias>>#name)])

Obviously this still has to generate a bunch of AS clauses in the SQL, but you don't have to worry about what they are.

Read: Aliasing

Topic: RSS Winterfest links Previous Topic   Next Topic Topic: Re: Service Oriented Architectures vs. Distributed Object Technologies

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use