---------- Forwarded message ----------
From: Stanislav Muhametsin <[email protected]>
Date: Sat, Oct 23, 2010 at 4:27 PM
Subject: QI-272
To: Niclas Hedhman <[email protected]>


Quoting "Niclas Hedhman (JIRA)" <[email protected]>:
  [
>
> http://issues.ops4j.org/browse/QI-272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13609#action_13609
>  ]
>
> Niclas Hedhman commented on QI-272:
> -----------------------------------
>
> I find your pattern very 'odd', and I am too tired right now to even try to 
> understand how you came to this modeling decision.
>
> If you want to limit the number of available instances, you should simply 
> prohibit it, either via a Constraint or by throwing an Exception in lifecycle 
> methods. Modifying Identity is not the way to go, IMNSHO.
>

Hmm, how can I prohibit it via a Constraint? IIRC they only affect
parameters of methods.

The pattern is to exploit the uniqueness of identity() property (since
there is no way in Qi4j to express uniqueness of some property - that
would have
solved it too) in order to ensure that certain other properties are
unique for this entity type. Other way is, inside create(), get all
entities of current entity type (via query - this adds more load as
querying service is required), and ensure that none of them has
certain values in certain properties. Quite inefficient and cumbersome
way to do it. Via modifying identity directly, you don't need query
service and you don't need querying, you simply make it unique using
the natural constraint for entites - that each entity must have unique
identity.

Maybe this is time to introduce @Unique annotation for properties?
That would be maybe the best way to handle this. Something like
@Unique(Scope.ENTITY_TYPE) (as opposed to, say, Scope.ROLE, which
means that all entites, no matter what type, must have unique
property). However, this would still need querying-service.




-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

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

Reply via email to