I haven't actually tried it using xml meta-data so please let me know how it
goes.  If you're willing to associate the sequence with a specific class you
can certainly do it using annotations:
There are a number of examples in this test class:
http://code.google.com/p/datanucleus-appengine/source/browse/trunk/tests/org/datanucleus/test/SequenceExamplesJDO.java

Note that if you want to avoid an rpc to the datastore every time you get
the next value from the sequence (and you might as well since there's really
no need to incur this cost) you'll want to get a handle to the Sequence and
hold on to it, probably in a static.  You'll also want to configure the
batch size of the sequence to be of a size that is appropriate for your
application.

Hope this helps,
Max
On Mon, Sep 7, 2009 at 11:03 AM, Erem <ehb...@gmail.com> wrote:

>
> Hey guys,
>
> I wanted to use a JDO persistence-backed Sequence to provide
> monotonically increasing visitor #'s in my webapp. A static variable
> doesn't cut it because I want the number to survive redeployments,
> upgrades, etc.
>
> I didn't see any info on Sequence in the wiki "Using JDO" section so I
> did this. It works but it seemed kinda hacky. Is this the best way to
> configure a JDO-backed Sequence in AppEngine?
>
> (FWIW I'm using the eclipse plug-in.)
>
> (1) Make the following file: MyProject/META-INF/package.jdo
>    * This directory should already contain a "jdoconfig.xml".
>    * Both files will be autoplaced into MyProject/war/WEB-INF/classes/
> META-INF on deploy.
>
> (2) Paste the following XML into package.jdo:
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <jdo xmlns="http://java.sun.com/xml/ns/jdo/jdo";
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>    xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdo
> http://java.sun.com/xml/ns/jdo/jdo_2_2.xsd";>
>        <!-- name the package whatever you want -->
>        <package name="MyProject">
>                <sequence name="VisitorSequence"
>                                   datastore-
> sequence="VISITOR_SEQUENCE"
>                                   strategy="contiguous"
>                 />
>        </package>
> </jdo>
>
> (3) When you need the next value in your application, call:
>
> PersistenceManager pm = //...allocate pm
>
> //the sequence name is <package name>.<sequence name>
> //from the corresponding tags in package.jdo
> Sequence seq = pm.getSequence("MyProject.VisitorSequence");
>
> //If "strategy" from package.jdo was "contiguous", this has to happen
> //in a transaction.
> long nextValue = seq.nextValue();
> >
>

--~--~---------~--~----~------------~-------~--~----~
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-java@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to