Den 26. nov. 2010 kl. 12.00 skrev Rickard Öberg:

> On 2010-11-16 13.28, Ronnie Nessa wrote:
>> I finally got around to write a testcase. Hope this makes it easier to 
>> debug. The project is attached to this email.
> 
> A couple of questions: if an entity that gets a callback loads another 
> entity, do you then expect that entity to also be included in the checks, 
> i.e. if *that* entity in turn implements UnitOfWorkCallback, does it get 
> added to the checks? Also, I assume that these loaded entities could be 
> changed during the callback, and if so, should be stored? Which makes things 
> REALLY TRICKY since the second callback is after state has been committed, 
> i.e. too late.
> 

I guess it would be ok to not include objects loaded during completion callback 
to the checks. But your point is valid, it seems tricky to implement this 
correctly. 


> Something feels really wrong here.
> 
> Why are you doing these callbacks in the first place? What is the problem you 
> are trying to solve?

I´m using the UnitOfWorkCallback for a couple of things. First I´m using it for 
validation of entities upon completion of the UoW (I´m using the 
UoWCallbackValidatableMixin from the qi4j-lib-validation module).

Also I have some entities that may have different statuses depending on where 
it is in the lifecycle. Most of the status changes happen at specific places in 
the workflow which makes it easy to implement the status changes, but one 
specific status is computed based on the completeness of the objects data, 
since we don´t have any "save"-method in our code i couldn´t find any good 
place to put this functionality. First I tried using computed properties, but 
found out that it could not support my usecase since computed properties isn´t 
indexed. Then I tried implementing it with  a UnitOfWorkCallback:

@Override
    public void beforeCompletion() throws UnitOfWorkCompletionException {
        if 
(dimensions.isDimensionsWithOutContextsComplete(ContextType.AUCTION_FLOW)) {
            auctionTransferable.onCompletionEvent(CompletionEvent.completed);
        } else {
            auctionTransferable.onCompletionEvent(CompletionEvent.incomplete);
        }
        next.beforeCompletion();
    }

Even though it´s not pretty, this works most of the time. But every now and 
then it fails because the query 
dimensions.isDimensionsWithOutContextsComplete(ContextType.AUCTION_FLOW) in 
some cases loads entitystate that has not previously been loaded. I think that 
this happens when the entity is loaded into a UoW only via an reference from 
another entity. 

I guess this could been done in a better way. If you have any pointers to a 
better implementation I´ll be happy to receive them. 


Best regards
Ronnie




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

Reply via email to