Package org.jivesoftware.database
Class SequenceManager
- java.lang.Object
-
- org.jivesoftware.database.SequenceManager
-
public class SequenceManager extends Object
Manages sequences of unique ID's that get stored in the database. Database support for sequences varies widely; some don't use them at all. Instead, we handle unique ID generation with a combination VM/database solution.A special table in the database doles out blocks of unique ID's to each virtual machine that interacts with Jive. This has the following consequences:
- There is no need to go to the database every time we want a new unique id.
- Multiple app servers can interact with the same db without id collision.
- The order of unique id's may not correspond to the creation date of objects.
- There can be gaps in ID's after server restarts since blocks will get "lost" if the block size is greater than 1.
- Author:
- Matt Tucker, Bruce Ritchie
-
-
Constructor Summary
Constructors Constructor Description SequenceManager(int seqType, int size)
Creates a new DbSequenceManager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static long
nextID(int type)
Returns the next ID of the specified type.static long
nextID(Object o)
Returns the next id for an object that has defined the annotationJiveID
.long
nextUniqueID()
Returns the next available unique ID.static void
setBlockSize(int type, int blockSize)
Used to set the blocksize of a given SequenceManager.
-
-
-
Method Detail
-
nextID
public static long nextID(int type)
Returns the next ID of the specified type.- Parameters:
type
- the type of unique ID.- Returns:
- the next unique ID of the specified type.
-
nextID
public static long nextID(Object o)
Returns the next id for an object that has defined the annotationJiveID
. The JiveID annotation value is the synonymous for the type integer.The annotation JiveID should contain the id type for the object (the same number you would use to call nextID(int type)). Example class definition:
\@JiveID(10) public class MyClass { }
- Parameters:
o
- object that has annotation JiveID.- Returns:
- the next unique ID.
- Throws:
IllegalArgumentException
- If the object passed in does not definedJiveID
-
setBlockSize
public static void setBlockSize(int type, int blockSize)
Used to set the blocksize of a given SequenceManager. If no SequenceManager has been registered for the type, the type is verified as valid and then a new sequence manager is created.- Parameters:
type
- the type of unique id.blockSize
- how many blocks of ids we should.
-
nextUniqueID
public long nextUniqueID()
Returns the next available unique ID. Essentially this provides for the functionality of an auto-increment database field.- Returns:
- the next sequence number
-
-