Re: [appengine-java] Re: Task queue + datastore transaction + jdo: is it possible?

2011-01-12 Thread Fabrizio Accatino
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  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  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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com
> .
> 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Task queue + datastore transaction + jdo: is it possible?

2011-01-11 Thread Ed Murphy
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  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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Task queue + datastore transaction + jdo: is it possible?

2011-01-11 Thread Didier Durand
Hi,

I personally do it with a higher-level 3rd party package (Objectify)
and it works.

Generally, my understanding is that you can associate transactionally
the insertion of a task in a queue and a transaction on the datastore
(whatever the interface to the datastore): if transaction commits,
tasks is inserted and then executed.If transaction rolls back, then
task is not inserted and not executed.

regards

didier

On Jan 11, 6:45 pm, Fabrizio Accatino  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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.