Package org.jenkinsci.plugins.uniqueid
Class IdStore<T>
- java.lang.Object
-
- org.jenkinsci.plugins.uniqueid.IdStore<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
ExtensionPoint
- Direct Known Subclasses:
PersistenceRootIdStore
,RunIdStore
,UserIdStore
public abstract class IdStore<T> extends Object implements ExtensionPoint
An abstraction to persistently store and retrieve unique id's for various Jenkins model objects. These keys are guaranteed to be unique with a Jenkins and immutable across the lifetime of the given object. Implementations should not store the ID inside any specific item configuration as it is common for users top copy items either through the UI or manually and this will cause the IDs to become non-unique.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static String
fileName()
Returns the generic filename that a store should use for storing the unique id.static <C> IdStore<C>
forClass(Class<C> clazz)
Retrieve anIdStore
for the given type.protected static String
generateUniqueID()
Generates a new unique ID.abstract String
get(T object)
Get the id for this given object.static String
getId(Object object)
Convenience method which retrieves the id for the given object.abstract void
make(T object)
Creates an unique id for the given object.static void
makeId(Object object)
Convenience method which makes the id for the given object.boolean
supports(Class clazz)
-
-
-
Method Detail
-
make
public abstract void make(T object)
Creates an unique id for the given object. Subsequent calls are idempotent.- Parameters:
object
- the object to make the id for.
-
get
@Nullable public abstract String get(T object)
Get the id for this given object.- Parameters:
object
- the object.- Returns:
- the id or
null
if none assigned.
-
supports
public boolean supports(Class clazz)
-
forClass
@Nullable public static <C> IdStore<C> forClass(Class<C> clazz)
Retrieve anIdStore
for the given type.- Type Parameters:
C
- the type of object.- Parameters:
clazz
- the type of object.- Returns:
- the store which supports the type, or
null
if none.
-
makeId
public static void makeId(Object object) throws IllegalArgumentException
Convenience method which makes the id for the given object.- Throws:
IllegalArgumentException
- if the type is not supported.
-
getId
public static String getId(Object object) throws IllegalArgumentException
Convenience method which retrieves the id for the given object.- Throws:
IllegalArgumentException
- if the type is not supported.
-
fileName
@Nonnull public static String fileName()
Returns the generic filename that a store should use for storing the unique id.- Returns:
- the generic filename.
- Since:
- 2.1.0
-
generateUniqueID
protected static String generateUniqueID()
Generates a new unique ID. Subclasses do not need to use this to create unique IDs and are free to create IDs by other methods.- Returns:
- a string that should be unique against all jenkins instances.
-
-