Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » OCL query with EDate
OCL query with EDate [message #415097] Thu, 29 November 2007 13:37 Go to next message
Eclipse UserFriend
Originally posted by: bryan.bulten.ca

Hello,

I am trying to use OCL for queries in which the application user will pick
a query and enter specific parameters.

For a simple query to find users in the system created after a specified
date,

"self.userAccount->select(creationDate > '???')"

I am unsure how to go about entering a literal for creationDate (type is
EDate).

I've tried:

"self.userAccount->select(creationDate.getTime() > 1234567)"

in an attempt to convert the EDate to a long for comparison in OCL, but am
told that the operation 'getTime' does not exist for type 'EDate'.

I'm new to EMF and OCL, and am not sure if I'm going about this the right
way. Is there a better method/tool for this type of query?


Thanks,
Bryan
Re: OCL query with EDate [message #415100 is a reply to message #415097] Thu, 29 November 2007 14:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Bryan,

OCL doesn't have a representation for date literals. I suggest using a
variable in your expression, for which you provide the date value when
executing the query.

So, you can do the following OCL expression:

self.userAccount->select(creationDate > _date_)

The tricky part comes next :-)

Construct your BooleanOCLCondition with an Environment that has the "_date_"
variable defined and a Query (from OCL API) that has an
EvaluationEnvironment supplying the value for the "_date_" variable, using
the BooleanOCLCondition(Environment,Query,C,PruneHandler) constructor.

Something like this (not real, tested code):

OCL<...> ocl = OCL.newInstance(...);

Environment<...> env = ocl.getEnvironment();

Variable<...> dateVar = env.getOCLFactory().createVariable();
dateVar.setName("_date_");
dateVar.setType(EcorePackage.Literals.EDATE);

env.addElement(dateVar.getName(), dateVar, true);

OCLHelper<...> helper = OCL.createOCLHelper();
helper.setContext(/* "self" type */);

Constraint constraint = helper.parseInvariant(
"self.userAccount->select(creationDate > _date_)");

Query<...> query = ocl.createQuery(constraint);
query.getEvaluationEnvironment().add(dateVar.getName(), theDateValue);

BooleanOCLCondition cond = new BooleanOCLCondition(
env, query, /* "self" type */, PruneHandler.NEVER);

... construct the SELECT statement ---

When you get this working, it will be a great contribution to the OCL Query
Example for the SDK! (hint, hint)

HTH,

Christian

Bryan Bulten wrote:

> Hello,
>
> I am trying to use OCL for queries in which the application user will pick
> a query and enter specific parameters.
>
> For a simple query to find users in the system created after a specified
> date,
>
> "self.userAccount->select(creationDate > '???')"
>
> I am unsure how to go about entering a literal for creationDate (type is
> EDate).
>
> I've tried:
>
> "self.userAccount->select(creationDate.getTime() > 1234567)"
>
> in an attempt to convert the EDate to a long for comparison in OCL, but am
> told that the operation 'getTime' does not exist for type 'EDate'.
>
> I'm new to EMF and OCL, and am not sure if I'm going about this the right
> way. Is there a better method/tool for this type of query?
>
>
> Thanks,
> Bryan
Re: OCL query with EDate [message #415101 is a reply to message #415100] Thu, 29 November 2007 14:07 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Bryan,

I hope your newsreader doesn't do what mine does, which is to show an
underline under the word "date" instead of the leading and trailing
underscore. Imagine <underscore>date<underscore> ...

cW
Previous Topic:recommendation on custom factory methods
Next Topic:Updating custom label text
Goto Forum:
  


Current Time: Fri Apr 19 02:23:09 GMT 2024

Powered by FUDForum. Page generated in 0.02386 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top