### UID

code

docs

tests

This library provides Services to easily generate unique identifiers and sequences of numbers.

Table 53. Artifact

Group ID | Artifact ID | Version
--- | --- | ---
org.qi4j.library | org.qi4j.library.uid | 2.1

#### Unique Identifiers

Assembly is done using the provided Assembler:

    new UuidServiceAssembler().visibleIn( layer ).assemble( moduleAssembly );

Usage is quite simple:

    @Service UuidService uuidService;

    public void doSomething()
    {
        String id1 = uuidService.generateUuid( 0 );
        // eg. 1020ECBB-098C-46E0-94DC-F78E2265EAA1-36

        String id2 = uuidService.generateUuid( 12 );
        // eg. 84E06578EAE3
    }

#### Sequencing

Sequencing is used to automatically generate a sequence of numbers.

The algorithm is that `currentSequenceValue` is the number that was last returned in a `newSequenceValue` call, and will initially be zero. Persisting Sequencing services defines "initially" as the first run ever, as subsequent starts may retrieve the `currentSequenceValue` from an EntityStore.

##### Transient Sequences

Assembly is done using the provided Assembler:

    new TransientSequencingAssembler().visibleIn( layer ).assemble( moduleAssembly );

Usage is quite simple:

    @Service Sequencing sequencing;

    public void doSomething()
    {
        sequencing.currentSequenceValue(); // return 0

        sequencing.newSequenceValue(); // return 1
        sequencing.currentSequenceValue(); // return 1
    }

##### Persisted Sequences

Assembly is done using the provided Assembler:

    new PersistingSequencingAssembler().visibleIn( layer ).assemble( moduleAssembly );

Usage is quite simple:

    @Service Sequencing sequencing;

    public void doSomething()
    {
        sequencing.currentSequenceValue(); // return 0

        sequencing.newSequenceValue(); // return 1
        sequencing.currentSequenceValue(); // return 1
    }