New Posts New Posts RSS Feed: Add Another constructor in the Factory class of Cocktail.Contrib
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Add Another constructor in the Factory class of Cocktail.Contrib

 Post Reply Post Reply
Author
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Topic: Add Another constructor in the Factory class of Cocktail.Contrib
    Posted: 27-Apr-2012 at 12:37am
Hi,

Actually the Factory class has only one constructor taking an EntityManagerProvider.

That makes it impossible to use the factories in the SampleDataProviders since there we only have an EntityManager. Could it be possible to add another constructor taking an EntityManager ? 
This constructor could be accessible only when the #FAKE conditional variable is set to avoid unauthorize use in the "real" application.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 27-Apr-2012 at 12:28pm
Using the Factory in a SampleDataProvider makes no sense. The factory creates "new" entities where as a SampleDataProvider fakes existing entities. You see the difference in how they get added to the EntityManager. The factory calls AddEntity where as in a SampleDataProvider you use AttachEntity. The difference is if you use AddEntity, the entity will be in the added state ready to be inserted into the database. AttachEntity on the other hand sets the entity state to unchanged. This is important, because sample data is supposed to fake a real database where the entities have already been inserted are are therefore in unchanged state.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 27-Apr-2012 at 12:36pm
Oh and the Factory in CocktailContrib follows the asynchronous pattern, where as setting up the sample data is all synchronous.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 27-Apr-2012 at 12:41pm
you are right, I totally forgot about the AddEntity/AttachEntity issue. I focused in the different task I do in the factory to create/initialize the entities and wanted to be sure the entities created in the SampleDataProvider followed the same rules as in the factory. Often when we modify the Factory we don't always remember to modify the SampleDataProvider too.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down