com.googlecode.objectify.util
Class Monotonic

java.lang.Object
  extended by com.googlecode.objectify.util.Monotonic

public class Monotonic
extends java.lang.Object

Provides a method for generating contiguous, monotonically increasing values.

The datastore will automatically generate unique ids for your entities if you use a Long @Id value and create an object with a null id. Unfortunately this id is not guaranteed to increase monotonically, so you cannot use it for time-ordering. You also cannot use datestamps for time-ordering because clock skew among GAE instances is not guaranteed to fall within any particular bound; they could, in theory, be minutes off.

This class uses the memcache service to efficiently generate a monotonically increasing number which *can* be used for time-ordering. This can be used, for example, to create revision ids. It can also be used to generate the change numbers needed to keep a slave database in sync.

The data must be stored on a field of an entity. The field MUST be indexed.

Author:
Jeff Schnitzer

Constructor Summary
Monotonic()
           
 
Method Summary
static long next(Objectify ofy, java.lang.Class<?> entityClass, java.lang.String fieldName)
          Get the next unique, monotonically increasing, contiguous value for a field on an entity class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Monotonic

public Monotonic()
Method Detail

next

public static long next(Objectify ofy,
                        java.lang.Class<?> entityClass,
                        java.lang.String fieldName)
Get the next unique, monotonically increasing, contiguous value for a field on an entity class. The field MUST be indexed or this method will always return 1.



Copyright © 2011 Jeff Schnitzer and a gang of pirates. All Rights Reserved. Build version: 3.1