Axon-trader example: no implementation of unique username constraint

Hi,

First, thanks for great CQRS framework.
I really admire your work.

On wiki page of Axon-trader example:
https://github.com/AxonFramework/Axon-trader/wiki/Architecture
there is said that:
“When receiving a command to create a new user,
we first check against a special collection to see if the username is still available.
After validation we actually create the user.”

… but there is no such a logic in related command handler:
https://github.com/AxonFramework/Axon-trader/blob/master/users/src/main/java/org/axonframework/samples/trader/users/command/UserCommandHandler.java#L41

Maybe I missed something but I could really use a reference solution for this problem.

Regards,
Paweł

Hi Pawel,

I think you’re right about the check missing there. Looks like we forgot to implement that.

To apply set validation, as this type of ‘uniqueness check’ is called, you need to create a simple table of used values, in which you add a value when an aggregate is changed. This table is your uniqueness guarantee.

There is an example in the Addressbook sample. The UnitOfWorkListerner is not needed if you use a transactional datasource.
https://github.com/AxonFramework/Addressbook-Sample/blob/master/app/src/main/java/org/axonframework/sample/app/command/ContactCommandHandler.java

Cheers,

Allard