> Hi,
> I'm trying to do a method with an OCL that returns an object.
> The OCL assigned to the method is the following:

> context
> Personas::findByFechaEdadYDNI(fecha:Date,edad:Integer,dni:String):Personas
> body : allInstances()-> select ( persona | persona.fnacimiento <= fecha
> and (persona.ffallecimiento > fecha or persona.ffallecimiento = null)
> and persona.edad = edad) and persona.dni = dni
>

> I know that this select is going to return just one instance... so I
> don't want a collection of objects with one object, I just want the
> object.
>

if you model the finder method to have the 'Personas' type then you're
safe, if the database would ever return more than one element it will
throw an exception (check the finder DAO base class)

> The method (in the diagram) that holds this constraint returns the
> correct type and receives the corrects parameters (also their types).

okay, good

> I'm getting two problems.
> First, the signature of the result method returns the correct type
> Personas, but the implementation still doing return query.list();
> This causes a compilation error of the generated source because of the
> types diference between the method signature and the returned type of
> list method.
>

that could be due to the fact that your query is a bit malformed, try
putting the trailing 'and persona.dni = dni' before the closing ')'

> Second, the *= null* clause is translated as is. I'm using PostgreSQL
> and this sentence doesn't work. I need *= null* to be translated into
> *is null*
>

= null does not exist in OCL, you should try
'persona.ffallecimiento->isEmpty()' (->isEmpty() works on all instances,
it's predefined OCL construct but mainly used on collections)

likewise, you also have the '->notEmpty()' construct, which does exactly
the opposite

-- Wouter



-------------------------------------------------------
This SF.net email is sponsored by: 2005 Windows Mobile Application Contest
Submit applications for Windows Mobile(tm)-based Pocket PCs or Smartphones
for the chance to win $25,000 and application distribution. Enter today at
http://ads.osdn.com/?ad_idh82&alloc_id148&op=click
_______________________________________________
Andromda-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/andromda-user

Reply via email to