gr8crm / grails-sequence-generator

A Grails 3 plugin that provide sequence numbers (customer, order, invoice) to Grails applications
0 stars 5 forks source link

= Grails Sequence Generator Plugin

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 https://github.com/goeh/grails-sequence-generator[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.

== Examples

[source,groovy]

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') == 104

The SequenceGeneratorService implementation is very efficient and can provide sequential numbers to concurrent threads without problems.

You will find more information in the https://github.com/gr8crm/grails-sequence-generator/blob/master/src/docs/asciidoc/index.adoc[developer guide].