Chad Brandon dijo lo siguiente el 23/03/2005 15:14:
Bruno Suárez Laffargue wrote:

Wouter Zoons dijo lo siguiente el 23/03/2005 13:01:

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)
 

I've looked into the templates, and I think that this DAO base class is generated only for spring cartidge (correct me if i am wrong) and I am not using it. I'm using hibernate cartridge.
I have the finder method generated into PersonasFactory.java.

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 ')'
 

I've corrected the query, but I still getting compilation error.
the method is:
public static test.mispruebas.Personas findByFechaEdadYDNI(net.sf.hibernate.Session session, java.util.Date fecha, java.lang.Integer edad, java.util.String dni)
{
   [...]
   return query.list();
}

this can not compile... :'-(

Yeah that's because you're using the hibernate cartridge which doesn't support single return types in the hibernate factory class.  Can you file a JIRA issue and assign it to me to add this support (so it's like the spring cartridge in that respect?)
Yes it is. I'll fill an issue right now :-)


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
 

Ok, I'd tried it, but... if I put: persona.ffallecimiento->isEmpty() the translation is: size(persona.ffallecimiento) = 0... and that doesn't run on PostgreSQL
persona.ffallecimiento is a nullable attribute, and I want to select the ones having it set to null (ffallecimiento means death date... and not all the persons I have in the database are dead :-S)
I just want to check if the person is (or was) alive in the date I receive. Can I use isEmpty() also for attribute values, or is it only for collections?

Yes, its possible to model this in OCL (isEmpty() is valid on non collection types as well), however the the andromda-ocl-query-library does not yet support isEmpty() on non-collection types (its on my list of things to do),
Ok, by the way I can do the thing with an andromda.hibernate.query tagged value value and with an iteration over the returned Collection.
It will not suppose so much work to change it in the future.

Thank you very much
Bruno
------------------------------------------------------- This SF.net email is sponsored by Microsoft Mobile & Embedded DevCon 2005 Attend MEDC 2005 May 9-12 in Vegas. Learn more about the latest Windows Embedded(r) & Windows Mobile(tm) platforms, applications & content. Register by 3/29 & save $300 http://ads.osdn.com/?ad_id=6883&alloc_id=15149&op=click _______________________________________________ Andromda-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/andromda-user

Reply via email to