Re: Question about fetching
Re: Question about fetching
- Subject: Re: Question about fetching
- From: Chuck Hill <email@hidden>
- Date: Tue, 21 Jul 2009 07:09:17 -0700
On Jul 21, 2009, at 3:19 AM, Francesco Romano wrote:
Thanks to both.
I read that chapter in the Apple documentation.
If I understand correctly the globalID has its scope in the
editingcontext.
No. An EOEnterpriseObject has scope in an EOEditingContext, each is a
unique Java Object. An EOGlobalID is global in scope. It is used to
identify which EOEnterpriseObjects are the same across multiple
EOEditingContexts.
I don't know why but I create a new editing context for each page...
so this is bad.
I don't think that is bad. It really depends on how you are using them.
Should I keep a single editing context? (until a customer add the
first product in the cart I don't have a session.., so I don't have
access to session().defaultEditingContext()).
If a customer has not put a product in the cart there is nothing for
you to retain between requests. So creating a new EC on each page is
perhaps the correct thing to do.
To scale up, you probably want to cache some of your products at the
Application level. Project Wonder has useful classes for this.
Chuck
Except this problem, I can do this: (?)
Number pk = product.primaryKey(); //it's a string.. I'll cast to
number
EOEditingContext ec = ERXEC.newEditingContext()
EOEntity entity = EOModelGroup.defaultGroup().entityNamed("Product");
EOGlobalID gid = entity.globalIDForRow(new NSDictionary(pk,"id"));
Product p = (product) ec.faultForGlobalID(gid);
Thanks
Francesco
Hello Francesco;
You can construct an EOGlobalID from the primary key an fault it.
I would generally not advocate using the primary key in this manner
as it may be volatile owing to migration of schema or database
product migration. That concern aside, assuming you have a primary
key and it has an attribute name of "id";
Number pk = ???
EOEditingContext ec = ???
EOEntity entity = EOModelGroup.defaultGroup().entityNamed("FooBar");
EOGlobalID gid = entity.globalIDForRow(new NSDictionary(pk,"id"));
FooBar = (FooBar) ec.faultForGlobalID(gid);
Hope this helps.
cheers.
On 21/lug/09, at 11:24, Christian Trotobas wrote:
Hi Francesco
On 21 juil. 2009, at 09:56, Francesco Romano wrote:
Hi..
This is a simple (and maybe stupid) question.
No question is stupid on this list. Feel free to ask.
I'm doing an application (an e-commerce application.. maybe wo is
not the best choice, but I know java better than ruby..), and I've
some pages accessed with directaction.
WebObjects is a pretty good choice for ecommerce; take a look at
the Apple Store to be sure :)
Maybe I'm wrong, but I can pass values to a page only with the
url, so.. only strings.
In a page I select an EntityObject and I've to pass to the other
page.
If I can't pass the whole object, I would like to pass the primary
key, so fetching should be faster..
But.. I can get the key, but I can't fetch an Object with it's PK.
Now i pass a name (a description string..).. but it's not unique,
so even with low probability, there can be collisions..
You should use a product ID which would be unique, like a part
number for example. It will be usefull too for accounting purpose,
and not only for the app internals. As a unique key, the PK could
be used, but depending on the nature of your business, you might
want to avoid exposing PK on the web: they should be considered
both confidential and subject to changes for technical reasons
(though it is very unlikely to occur).
In WebObjects, the EOF framework provides a unique identifier for
EO: it is the EOGlobalID. Basically, it is a compound from the
EOEntity name and the PK from the table (out of the box, it is how
it works; for specific reason out of the scope of your question, it
happens that it is not the PK; again, it is very unlikeky to occur
for standard/simple uses, so don't bother about this, it was just
for information purpose). Therefore, in your app, if you are
looking for a unique identifier for your EO objects, you have to
use the EOGlobalID and not the PK. Understanding how EOF handles
the uniquing of objects is one the keys for your successfull
development with WebObjects.
Take a close look at:
http://developer.apple.com/documentation/Webobjects/Enterprise_Objects/Fetching/Fetching.html#/
/apple_ref/doc/uid/TP30001011-CH206-BADHCCEE
Hope that helps.
Christian Trotobas
What can I do?
Thanks
Francesco Romano
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
--
Chuck Hill Senior Consultant / VP Development
Learn WO at WOWODC'09 East in Montréal this August!
http://www.wocommunity.org/wowodc09/east
http://arstechnica.com/apple/news/2009/07/webobjects-sliced-from-106but-prognosis-of-death-premature.ars
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden