What is the recommended way to use transactions from a restlet?

Apparently they are not transactional by default, because throwing an exception 
after having done a CoreSession#createDocument() or CoreSession#saveDocument() 
has no effect, the document is created nonetheless.

I've found the class SimpleTxManager, and currently I'm using that, but I 
wondered if there is a way to declare the whole restlet as transactional, 
without having to start/commit/rollback manually.

Also, does it make a difference if the restlet uses Seam or not?

And finally, what is the difference between CoreSession#createDocument() (or 
CoreSession#saveDocument()) and CoreSession#save()? Is the latter always 
needed? The javadocs are not very explanatory...


I am testing with this code:

---

@Name("docCreationRestlet")
@Scope(ScopeType.EVENT)
public class DocCreationRestlet extends BaseNuxeoRestlet
{
   private static final Log log = LogFactory.getLog(DocCreationRestlet.class);

   @In(create = true)
   protected transient NavigationContext navigationContext;

   protected CoreSession documentManager;

   @Override
   public void handle(Request request, Response response)
   {
       [...]

       try
       {
           navigationContext.setCurrentServerLocation(new 
RepositoryLocation("default"));
           documentManager = navigationContext.getOrCreateDocumentManager();

           // let's create a document
           DocumentModel doc = documentManager.createDocumentModel("/", 
"some-id", "SomeType");
           documentManager.createDocument(doc);

           // is this needed?
           documentManager.save();

           throw new ClientException();
       }
       catch (Exception e)
       {
           // this certainly does not work!
           documentManager.cancel();
       }

       [...]
   }
}

---

Thanks for your time.

Daniel Pérez Álvarez

Technological Solutions
Atos Origin
+34 91 126 7290
C/ Albasanz, 16
28037 Madrid
Spain
------------------------------------------------------------------
This e-mail and the documents attached are confidential and intended 
solely for the addressee; it may also be privileged. If you receive 
this e-mail in error, please notify the sender immediately and destroy it. 
As its integrity cannot be secured on the Internet, the Atos Origin 
group liability cannot be triggered for the message content. Although 
the sender endeavours to maintain a computer virus-free network, 
the sender does not warrant that this transmission is virus-free and 
will not be liable for any damages resulting from any virus transmitted. 

Este mensaje y los ficheros adjuntos pueden contener informacion confidencial 
destinada solamente a la(s) persona(s) mencionadas anteriormente 
pueden estar protegidos por secreto profesional. 
Si usted recibe este correo electronico por error, gracias por informar 
inmediatamente al remitente y destruir el mensaje. 
Al no estar asegurada la integridad de este mensaje sobre la red, Atos Origin 
no se hace responsable por su contenido. Su contenido no constituye ningun 
compromiso para el grupo Atos Origin, salvo ratificacion escrita por ambas 
partes. 
Aunque se esfuerza al maximo por mantener su red libre de virus, el emisor 
no puede garantizar nada al respecto y no sera responsable de cualesquiera 
danos que puedan resultar de una transmision de virus. 
------------------------------------------------------------------

_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm
To unsubscribe, go to http://lists.nuxeo.com/mailman/options/ecm

Reply via email to