Jérémy,
The ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator() is to use
another database connection and to isolate the background process from the main
user interface process. If you use the default ObjectStoreCoordinator, you will
bloc the users with long database requests.
Even with another ObjectStoreCoordinator, your database server may impose lock
depending on your connection setting and SQL.
To refresh objects, you need to force a fetch in the default
ObjectStoreCoordinator, here is a code that should do it.
EOEditingContext _editingContextInDefaultEOObjectStore = new
EOEditingContext();
_editingContextInDefaultEOObjectStore.
setFetchTimestamp(System.currentTimeMillis()); // Tell the EC to fetch if
snapshot is older than now
_editingContextInDefaultEOObjectStore.lock(); // do not forget that
try {
EOGlobalID globalIdToRefresh =
_localCampaign.editingContext().globalIDForObject(_localCampaign);
EOEnterpriseObject refreshedObject =
_editingContextInDefaultEOObjectStore.objectForGlobalID(globalIdToRefresh);
}
finally {
_editingContextInDefaultEOObjectStore.unlock(); // do not forget that
}
I think invalidating the snapshots will only affect future instances not
existing ones.
Samuel
Le 2013-08-27 à 07:14, Jérémy DE ROYER <[email protected]> a écrit :
> Hello,
>
> According the the thread below :
> - http://lists.apple.com/archives/webobjects-dev/2008/Aug/msg00088.html
> and the slide :
> - http://fr.slideshare.net/wocommunity/background-tasks
>
> Only when using new
> EOEditingContext(ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator())
> instead of new EOEditingContext(new EOObjectStoreCoordinator()) will
> propagate changes.
> ("Create a new ObjectStoreCoordinator (use Wonder OSC synchronization if you
> want changes to propogate)")
>
> So I develop a new thread (for sending mass emails without slowing down all
> the users as currently)
>
> I used :
>
> a)
>
> I use new
> EOEditingContext(ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator())
> for the thread
>
>
> b)
>
> I add the code below each time I want changes to be propagated.
>
> EOEditingContext _editingContextInDefaultEOObjectStore = new
> EOEditingContext();
> _editingContextInDefaultEOObjectStore.invalidateObjectsWithGlobalIDs(new
> NSArray(new Object[]{
> _editingContextInThreadObjectStoreCoordinator().globalIDForObject(_localCampaign)
> }));
> _editingContextInDefaultEOObjectStore.invalidateObjectsWithGlobalIDs(new
> NSArray(new Object[]{
> _editingContextInThreadObjectStoreCoordinator().globalIDForObject(_localCampaign._campagneTask())
> }));
>
> try {
> _editingContextInDefaultEOObjectStore.saveChanges();
> }
> catch (Exception e) {
> e.printStackTrace();
>
> _editingContextInDefaultEOObjectStore.revert();
> }
>
> My task works well, changes are saved in the database…
>
> …but changes are only propagate to the users (in the default EOObjectStore)
> when the do saveChanges() to their editingContext();
>
> I tried using
> ERXEC.newEditingContext(ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator());
> without any success.
>
> Any idea where am I wrong ?
>
> Jérémy
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/samuel%40samkar.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]