Skip navigation links

Package com.technia.tvc.core.db.numgen

Contains functionality for generating unique numbers, used when creating new business object instances.

See: Description

Package com.technia.tvc.core.db.numgen Description

Contains functionality for generating unique numbers, used when creating new business object instances.

A certain business-type, can have a set of number generators associated. These numbergenerators are represented themselves by businessobjects of type "TVC Number Generator Settings".

To associate a new number generator to be used for when creating business objects of a certain type, simply add such a number generator by running following MQL/TCL code:

    mql add bus                                 \
        "TVC Number Generator Settings"         \
        "type_MyType"                           \
        "A-Size"                                \
        vault "TVC Administration"              \
        policy "TVC Number Generator Settings"  \
        "TVC Number" "0"                        \
        "TVC Digits" "16"                       \
        "TVC Prefix" "A-"                       \
        "TVC Suffix" "-XXX"

This number generator is associated to the type (or any sub-type) registered through the symbolic name: type_MyType. You can either use symbolic names, or real names.

The name of this number generator is "A-Size".

This number generator creates numbers according to this format: A-0000000000000001-XXX

Explanation:

name (type_MyType)
The type which can use this generator (type_MyType)
revision (A-Size)
Each type can have several number generators. Simply add as many number generator objects you need.
vault (TVC Administration)
The object must be created inside this vault
policy (TVC Number Generator Settings)
This policy must be used for these objects
TVC Number
Stores the current number. When creating the object, use 0 as the start number. Never change this number on a number generator that is in use
TVC Digits
Defines the number of digits to represent the number in
TVC Prefix
Defines the static text to be added as a prefix before the number
TVC Suffix
Defines the static text to be added as a suffix after the number

When allocating new numbers using a number generator, you can simply do following:

    NumberGenerators ng = NumberGenerators.get(type);
    NumberGenerator gen = ng.getByName("A-Size");
    String number = gen.allocate();

OR:

    NumberGenerators ng = NumberGenerators.get(type);
    NumberGenerator gen = ng.findMostSuitable(1); // 1 = the number of "numbers" to generate
    String number = gen.allocate();

If you want to allocate more than one number, and you know the amount of numbers to be generated, then you can do this by using the following code example. (Please note that this approach is much faster than allocating the numbers in a loop, one-by-one).

    NumberGenerator gen = ...
    NumberRange range = gen.allocate(100); // allocate 100 numbers...
    Iterator<String> itr = range.getNumbers();
    while (itr.hasNext()) {
        String number = itr.next();
    }
Skip navigation links

Copyright ? Technia AB. All Rights Reserved.