• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about fetching
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about fetching


  • Subject: Re: Question about fetching
  • From: Christian Trotobas <email@hidden>
  • Date: Tue, 21 Jul 2009 12:43:11 +0200


On 21 juil. 2009, at 12:19, 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.
I don't know why but I create a new editing context for each page... so this is bad. 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()).

Take a look at EOSharedEditingContext. Seems to me this is what you are looking for.
http://devworld.apple.com/documentation/InternetWeb/Reference/WO542Reference/com/webobjects/eocontrol/EOSharedEditingContext.html


Search the mailing list for EOSharedEditingContext, too.


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);
Looks good. But Andrew's advice was more an example on how things work, rather than an advise on what exactly your code should look like.
Use a shareEditingContext for Products, then a simple defaultEditingEditing from your Session to store the cart.


Christian


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

_______________________________________________ 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
  • Follow-Ups:
    • Re: Question about fetching
      • From: Francesco Romano <email@hidden>
References: 
 >Question about fetching (From: Francesco Romano <email@hidden>)
 >Re: Question about fetching (From: Christian Trotobas <email@hidden>)
 >Re: Question about fetching (From: Francesco Romano <email@hidden>)

  • Prev by Date: Re: Question about fetching
  • Next by Date: Re: Question about fetching
  • Previous by thread: Re: Question about fetching
  • Next by thread: Re: Question about fetching
  • Index(es):
    • Date
    • Thread