[Modeling-cvs] ProjectModeling/Modeling/doc/UserGuide ManipulatingGraphOfObjects.tex,1.13,1.14
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-07-17 12:39:43
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/doc/UserGuide
In directory sc8-pr-cvs1:/tmp/cvs-serv28239/doc/UserGuide
Modified Files:
ManipulatingGraphOfObjects.tex
Log Message:
Documentation for fetching raw rows part 2
Index: ManipulatingGraphOfObjects.tex
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/doc/UserGuide/ManipulatingGraphOfObjects.tex,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** ManipulatingGraphOfObjects.tex 16 Jul 2003 23:32:17 -0000 1.13
--- ManipulatingGraphOfObjects.tex 17 Jul 2003 12:39:40 -0000 1.14
***************
*** 20,24 ****
An other feature assumed by \class{EditingContext}s is that they make sure
! that an given object has a single instance within them. So, if you fetch a
particular object, then later access the same object e.g. by traversing some
relationships, you are sure that the two are the same object (exactly the
--- 20,24 ----
An other feature assumed by \class{EditingContext}s is that they make sure
! that a given object has a single instance within them. So, if you fetch a
particular object, then later access the same object e.g. by traversing some
relationships, you are sure that the two are the same object (exactly the
***************
*** 45,49 ****
A A'
\end{verbatim}
! with \class{A} and \class{A'} having the same values.
--- 45,50 ----
A A'
\end{verbatim}
! with objects \class{A} and \class{A'} ultimately referring to the very same
! row in the database.
***************
*** 429,432 ****
--- 430,443 ----
it (e.g. for modification).
+ \begin{notice}
+ Of course, when fetching raw rows, you cannot benefit from most of the
+ framework's capabilities since it manipulates objects, not dictionaries; you
+ shoudl also note that the fetched data are not cached by the
+ framework. However, in some situations like the ones we saw above, it's just
+ what you want; moreover, it speeds up the fetch process, and reduces the
+ memory footprint to just what is needed.
+ \end{notice}
+
+
In this section we'll see how to do these both things: fetching raw rows and
turning a raw into a real object.
***************
*** 536,540 ****
\subsubsection{Turning rows into real objects\label{ec-fetch-turn-raw-row-to-object}}
! TBD
\section{Saving Changes\label{ec-save-changes}}
--- 547,595 ----
\subsubsection{Turning rows into real objects\label{ec-fetch-turn-raw-row-to-object}}
! Say you've presented to your user a large list of objects to choose from. Now
! the user selects one for modification or detailed inspection, probably
! including the objects in relations. There you need to get the magic on real
! objects back.
!
! This is easily done with \class{EditingContext}'s \method{faultForRawRow};
! continuing the previous example:
!
! \begin{verbatim}
! >>> raw_john=ec.fetch('Executive', 'firstName=="John"', rawRows=1)[0]
! >>> pprint.pprint(raw_john)
! {'firstName': 'John',
! 'fkStoreId': <Modeling.GlobalID.TemporaryGlobalID instance at 0x8364a0c>,
! 'id': 3,
! 'lastName': 'Cleese',
! 'officeLocation': '4XD7'}
! >>> john=ec.faultForRawRow(raw_john, 'Employee')
! >>> john
! <Executive.Executive instance at 0x8531db4>
! >>> john.getFirstName(),john.getLastName(),john.getToStore().getCorporateName()
! ('John', 'Cleese', 'We sell parrots')
! \end{verbatim}
!
! Here we converted a raw dictionary to a real object, which is automatically
! registered within the framework with all its normal capabilities, just as if
! you directly fetch()'ed it from the database.
!
! As you can see, \method{faultForRawRow()} takes a dictionary and the name of
! the entity the object belongs to, and returns the real object. Note that the
! entity's name shouldn't be exactly the right one: we asked for an
! \code{Employee}, we got an object of class/entity \code{Executive}, sub-entity
! of \code{Employee}. The only constraint on \code{entityName} is that it needs
! to belong to the same inheritance tree than the object's. This makes life
! easier when turning into objects raw rows which were fetched against a whole
! inheritance tree.
!
! For example, you may fetch raw rows for the whole hierarchy beyond entity
! 'Employee': the rows you'll get will belong to either entities 'Employee',
! 'SalesClerk' or 'Executive', but this information is not enclosed within the
! dictionaries themselves\footnote{except that, if the sub-entities have more
! attributes than their parent, you'll probably be able to guess to which entity
! a dictionary belongs to: for instance, only '\code{Executive}' objects have an
! attribute '\code{officeLocation}'.}. When turning the raws back to objects,
! just specify the root entity, and the object of the right class will be
! automatically returned.
\section{Saving Changes\label{ec-save-changes}}
|