Georg Ragaller wrote:
> Hi folks!
> 
> How can I have property constraints checked in UnitOfWork.complete()?
> Is there a ready-made fragment to do this? How can I 'weave' it in?
> 
> Sample:
> 
> public interface Book
> {
>      @NotEmpty Property<String> title();
>      @NotNull  Property<ISBN13> isbn();
> }
> 
> The following code works fine
> 
>      ...
>      UnitOfWork uow = uowf.newUnitOfWork();
>      Book book = uow.newEntity(BookEntity.class);
>      book.title().set("Qi4j in Action");
>      uow.complete();
>      ...
> 
> and the book.isbn() is never set, so the @NotNull constraint is never
> checked and null is stored.
> 
> That's ok for some kind of use-cases, let's say a wizard, where the user 
> has the ability to save the current wizard state and restart later where 
> he left.
> But there are other cases, where I wan't to assure that my entities 
> fullfill the property constraints at latest when uow.complete() is 
> performed.

I think the current bug is that constraints aren't checked for default 
values, and also are not checked upon instance creation. That is the 
real bug. In the above, you are creating an Entity, whereas you really 
should be creating a CompositeBuilder, set the properties using 
stateOfComposite() and only then call newInstance(). This way the 
constraints will be properly checked.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to