<html><body>
<DIV>I know this is a bit long for a post but I’m hoping someone will benefit from this.<SPAN style="mso-spacerun: yes"> </SPAN>I’m also interested in hearing your comments.</DIV>
<DIV> </DIV>
<DIV>The questions and comments that were made in today’s database sessions indicate that there are many developers who have a one track mind vision when it comes to database types.<SPAN style="mso-spacerun: yes"> </SPAN>There are those who swear by relational and then there are those who swear by object oriented ones.</DIV>
<DIV> </DIV>
<DIV>So who is right?<SPAN style="mso-spacerun: yes"> </SPAN>Well that all depends on the application.<SPAN style="mso-spacerun: yes"> </SPAN>Relational databases work great for some applications and object orient ones are great for others.<SPAN style="mso-spacerun: yes"> </SPAN>On the other hand using both types are sometimes the most appropriate approach.</DIV>
<DIV> </DIV>
<DIV>Typically people who write business applications tend to choose relational and those who write engineering/scientific applications use object oriented.<SPAN style="mso-spacerun: yes"> </SPAN>Fortunately both groups in general are choosing the correct types of database for their application domains.<SPAN style="mso-spacerun: yes"> </SPAN>This is a good thing as when you choose the wrong type of database you will tend to have to write a significant amount of unnecessary code and will likely have performance issues.</DIV>
<DIV> </DIV>
<DIV>The problem though, is some business applications could benefit from an object orient database.<SPAN style="mso-spacerun: yes"> </SPAN>Likewise, some engineering/science applications could benefit from a relational database.<SPAN style="mso-spacerun: yes"> </SPAN>It is very likely the type that is used will be the type that a particular domain prefers to use.<SPAN style="mso-spacerun: yes"> </SPAN>The decision should be made based on what type of querying is required to select and use that data once it is stored in the database.</DIV>
<DIV> </DIV>
<DIV>I will go over two trivial applications, one from each domain and will point out some of the pros and cons to storing the data in both types of database.</DIV>
<DIV> </DIV>
<DIV>The first application will be one that consists of drawings that are made with lines.<SPAN style="mso-spacerun: yes"> </SPAN>The class is shown next with a few instances of Line and a list to represent the drawing.</DIV>
<P class=MsoNormal>class Line(object):<BR> def __init__(self, x1, y1, x2, y2, red, green, blue):<BR> self.x1 = x1<BR> self.y1 = y1<BR> self.x2 = x2<BR> self.y2 = y2<BR> self.red = red<BR> self.green = green<BR> self.blue = blue</P>
<P class=MsoNormal>l1 = Line(0, 0, 1, 1, 255, 0, 0)<BR>l2 = Line(1, 1, 2, 2, 0, 255, 0)<BR>l3 = Line(2, 2, 3, 3, 0, 0, 255)</P>
<P class=MsoNormal>drawing = [l1, l2, l3]</P>
<P class=MsoNormal> </P>
<P class=MsoNormal><B>Object Oriented approach:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></B></P>
<P class=MsoNormal>Storage</P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Create a table to store drawings</LI>
<LI class=MsoNormal style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Pickle the drawing list</LI>
<LI class=MsoNormal style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Store pickle object with a key = drawingName</LI></UL>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal>Retrieval</P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Get pickle object with key = drawingName</LI>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Unpickle object</LI>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Use objects</LI></UL>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal>Pros: Only a couple lines of code needed for storage and retrieval is very fast</P>
<P class=MsoNormal>Cons: None</P>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal><B>Relational approach:<o:p></o:p></B></P>
<P class=MsoNormal>Storage</P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Create a table to store drawings</LI>
<LI class=MsoNormal style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Create a table to store lines</LI>
<LI class=MsoNormal style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Insert a new row of data into the drawings table storing an ID for a Primary key and name under drawingName</LI>
<LI class=MsoNormal style="mso-list: l0 level1 lfo1; tab-stops: list .5in">For each Line in drawing add a row to the lines table and insert the appropriate data</LI></UL>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal>Retrieval</P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Perform a query on the drawings and lines table to retrieve all line records associated with the drawing of interest.</LI>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Create an empty drawing list</LI>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Unpack the data for each row and create a Line Object</LI>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Append each Line object to drawing list</LI>
<LI class=MsoNormal style="mso-list: l1 level1 lfo2; tab-stops: list .5in">Use objects</LI></UL>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal>Pros: None (assuming there is no need to do arbitrarily queries on the endpoints and color properties)</P>
<P class=MsoNormal>Cons: Far more code to write than Object Oriented approach and retrieval is slower.</P>
<P class=MsoNormal>---</P>
<P class=MsoNormal>For the second application we will save information about some artists and instead of going through all the details of both database approaches I will just talk about the pros and cons.</P>
<P class=MsoNormal>class Person(objects):<BR> def __init__(self, name, age, address):<BR> self.name = name<BR> self.age = age<BR> self.address = address</P>
<P class=MsoNormal>p1 = Person(...)<BR>...<BR>p3 = Person(...)</P>
<P class=MsoNormal>lineArtists = [p1, p2, p3]</P>
<P class=MsoNormal><STRONG>Relational Approach</STRONG><BR>Pros: Very easy to create flexible searches<BR>Cons: Slower retrieval</P>
<P class=MsoNormal><STRONG>Object Orient Approach</STRONG><BR>Pros: Fast Retrieval<BR>Cons: It will take quite a bit of code in order to have a flexible querying capability.<BR></P>
<P class=MsoNormal>---</P>
<P class=MsoNormal> </P>
<P class=MsoNormal>The structure of the classes/objects in each application is similar yet in one case it makes sense to use an object oriented database and in the other a relational database.<SPAN style="mso-spacerun: yes"> </SPAN>The approach that was best for the application was based on the types of queries that were required.<SPAN style="mso-spacerun: yes"> </SPAN>In the first case only a query by drawingName was required and in the second case it was necessary to be able to perform flexible queries over all the fields.</P>
<P class=MsoNormal> </P>
<P class=MsoNormal>Now what would you do if you had an application that needed to store data on Artists who created line drawings and you also needed to save the line drawings.<SPAN style="mso-spacerun: yes"> </SPAN>Well you might want to think about using both database types to take advantages of their strengths.<SPAN style="mso-spacerun: yes"> </SPAN>Store the artist data in a relational database as well as the drawingNames for each drawing an Artist has created.<SPAN style="mso-spacerun: yes"> </SPAN>Then save the drawing data into an object database.<SPAN style="mso-spacerun: yes"> </SPAN>To retrieve drawing data for a particular drawing from a particular Artist, you would first query the relational database first to retrieve the drawingName.<SPAN style="mso-spacerun: yes"> </SPAN>Then retrieve the drawing from the object database using the drawingName as the key.<SPAN style="mso-spacerun: yes"> </SPAN>The best of both worlds.<SPAN style="mso-spacerun: yes"> </SPAN>The least amount of code and higher performance.</P></body></html>