The sequence generator plugin provides a simple way to add sequence counters to Grails 3 applications. You can control the starting number, the format and you can have different sequence counters based on application logic.
|
Note
|
This is the Grails 3 version of Grails 2 sequence-generator plugin. It’s a complete re-write but mostly backwards compatible with the older Grails 2 version, so you should be able to use it in Grails application that you upgraded from Grails 2 to Grails 3 with just minor adjustments to your application code. |
sequenceGeneratorService.initialize('WebOrder', null, null, 100, 'WEB-%04d')
assert sequenceGeneratorService.nextNumber('WebOrder') == 'WEB-0100'
assert sequenceGeneratorService.nextNumber('WebOrder') == 'WEB-0101'
assert sequenceGeneratorService.nextNumber('WebOrder') == 'WEB-0102'
assert sequenceGeneratorService.nextNumberLong('WebOrder') == 103
assert sequenceGeneratorService.nextNumberLong('WebOrder') == 104The SequenceGeneratorService implementation is very efficient and can provide sequential numbers to concurrent threads without problems.
You will find more information in the developer guide.