You may also want to look into sharded counters, which is the approach we've traditionally recommended for implementing hit counters or other monotonically increasing data:
http://code.google.com/appengine/articles/sharding_counters.html The article is in Python, but there is a Java demo available: http://code.google.com/p/googleappengine/source/browse/#svn/trunk/java/demos/shardedcounter - Jason On Mon, Sep 7, 2009 at 11:03 AM, Erem <[email protected]> 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 [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 -~----------~----~----~----~------~----~------~--~---
