Thank you very much. It works fine. :)
Only a note. In my tests I didn't pass the transaction when I call the
queue.add. It seems that queue.add "feels" the current transaction (see the
example at
http://code.google.com/appengine/docs/java/taskqueue/overview.html#Tasks_Within_Transactions
)
My code:
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.currentTransaction().begin();
// JDO
Query jdoquery = pm.newQuery(Friend.class);
.... get object x....
x.setLastUpdate(new Date());
pm.makePersistent(x);
// Queue
Queue queue = QueueFactory.getQueue("myqueue");
....
queue.add(taskOpts);
pm.currentTransaction().commit();
} finally {
if (pm.currentTransaction().isActive())
pm.currentTransaction().rollback();
pm.close();
}
Fabrizio
On Tue, Jan 11, 2011 at 9:29 PM, Ed Murphy <[email protected]> wrote:
> Yes, I do this with JDO. Just add to you queue within the current
> transaction, for instance;
>
> PersistenceManager pm = PMF.get().getPersistenceManager();
> try
> {
> //
> // start transaction so we can atomically check the secondary key
> //
> pm.currentTransaction().begin();
>
> //
> // enqueue a task to process this ImportTask
> //
> //
> String theUrl = "/tasks"; // whatever your url will be - this is is
> your state;
> Queue queue = QueueFactory.getDefaultQueue();
> queue.add(
>
> DatastoreServiceFactory.getDatastoreService().getCurrentTransaction(),
> TaskOptions.Builder.url(theUrl));
>
> //
> // commit the transaction.
> //
> pm.currentTransaction().commit(); // we finished, so commit
> the
> transaction.
> }
> catch(DataAccessException dae)
> {
> throw dae; // let prior DataAccessException leave.
> }
> catch(Exception e)
> {
> throw new DataAccessException(e); // wrap the exception in our
> runtime exception.
> }
> finally
> {
> //
> // if the transactions is still active, then there
> // was an exception thrown. So we rollback the transaction.
> //
> if(pm.currentTransaction().isActive())
> {
> pm.currentTransaction().rollback();
> }
>
> //
> // we always close the PersistenceManager when done.
> //
> if(!pm.isClosed())
> {
> pm.close();
> }
> }
>
>
> On Jan 11, 10:45 am, Fabrizio Accatino <[email protected]> wrote:
> > Hello,
> >
> > documentation tells I can insert a task in queue during a datastore
> > transaction.
> http://code.google.com/appengine/docs/java/taskqueue/overview.html#Ta...
> >
> > The example uses datastore low level api. Is there a way to do the same
> with
> > JDO?
> >
> > Thank you
> >
> > Fabrizio
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.