You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@abdera.apache.org by Chris Berry <ch...@gmail.com> on 2007/08/13 16:35:25 UTC

GData-style optimistic concurrency

Greetings,
I have implemented a GData-style Atom store on top of Abdera.
One of the better features of GData is it's optimistic concurrency  
model.
And it seems that Abdera might benefit from providing an abstraction  
around this concept,
similar to the other error codes (e.g. forbidden(), badrequest(), etc.)

I implemented the following (although it might be better to use a  
<content> element, than simply provide an edit link)
Thanks,
-- Chris 

     /**
      * Return a 409 conflict error
      */
     protected ResponseContext optimisticConcurrencyError( Abdera  
abdera, RequestContext request,
                                                                         
                                     String reason, String editURI ) {
         return returnBase( createOptimisticConcurrencyErrorDocument 
( abdera, reason, editURI ),
                                          409, null);
     }

     protected Document createOptimisticConcurrencyErrorDocument 
( Abdera abdera, String message, String editURI ) {

         Document doc = abdera.getFactory().newDocument();
         ExtensibleElement root = (ExtensibleElement)  
abdera.getFactory().newElement(ERROR, doc);
         root.addSimpleExtension( CODE, "409" );
         root.addSimpleExtension( MESSAGE, (message != null) ?  
message : "" );

         // create an Atom edit link
         Link link = abdera.getFactory().newLink();
         link.setHref( editURI );
         link.setRel( "edit" );

         if ( logger.isDebugEnabled() )
             logger.debug( "^^^^^^^^^^^^^^^^ link = " + link );

         root.addExtension( link );

         return doc;
     }




S'all good  ---   chriswberry@gmail.com




Re: GData-style optimistic concurrency

Posted by James M Snell <ja...@gmail.com>.
The optimistic concurrency model in Gdata works but using Etags/If-Match
is a better solution.  That said, I would not have a problem putting
some GData-specific code in the extensions model, perhaps a
GDataProvider that would extend AbstractProvider?

- James

Chris Berry wrote:
> Greetings,
> I have implemented a GData-style Atom store on top of Abdera.
> One of the better features of GData is it's optimistic concurrency model.
> And it seems that Abdera might benefit from providing an abstraction
> around this concept,
> similar to the other error codes (e.g. forbidden(), badrequest(), etc.)
> 
> I implemented the following (although it might be better to use a
> <content> element, than simply provide an edit link)
> Thanks,
> -- Chris
>     /**
>      * Return a 409 conflict error
>      */
>     protected ResponseContext optimisticConcurrencyError( Abdera abdera,
> RequestContext request,
>                                                                       
>                                     String reason, String editURI ) {
>         return returnBase( createOptimisticConcurrencyErrorDocument(
> abdera, reason, editURI ),
>                                          409, null);
>     }
> 
>     protected Document createOptimisticConcurrencyErrorDocument( Abdera
> abdera, String message, String editURI ) {
> 
>         Document doc = abdera.getFactory().newDocument();
>         ExtensibleElement root = (ExtensibleElement)
> abdera.getFactory().newElement(ERROR, doc);
>         root.addSimpleExtension( CODE, "409" );
>         root.addSimpleExtension( MESSAGE, (message != null) ? message :
> "" );
> 
>         // create an Atom edit link
>         Link link = abdera.getFactory().newLink();
>         link.setHref( editURI );
>         link.setRel( "edit" );
> 
>         if ( logger.isDebugEnabled() )
>             logger.debug( "^^^^^^^^^^^^^^^^ link = " + link );
> 
>         root.addExtension( link );
> 
>         return doc;
>     }
> 
> 
> 
> 
> S'all good  ---   chriswberry@gmail.com
> 
> 
> 
>