Query Translation-Library Modeling

The page describes the modeling standards one must follow to in order to use the Query Translation-Library.

In order for an expression to be written so that it can be translated in the correct manner, there are some guide lines that it must follow.

Guideline Explanation Example
Must be of type 'body'. An expression which translates to a query is in essence the body of a query operation. context Project::findByProjectType( projectTypeId:Long, requestStatus:String, compareDate:Timestamp):Collection(Project) body findByProjectType: allInstances() -> select ( project | project.projectType.id = projectTypeId and project.status = requestStatus and project.submittedDate >= compareDate )
After the context declaration, each expression must start with a 'allInstances() -> select(<some expression>)' This represents the beginning of the query and tells us that we are beginning with all instances of the Classifier element in which the query operation resides. context Project::findByNameAndNumber(name:String,number:String) : Collection(Project) body findByNameAndNumberBody: allInstances() -> select( project | StringUtils.isLike(project.projectName, name) and StringUtils.isLike(project.projectNumber, number) )
Translation to like statements require you add a StringUtils element to your model with an isLike operation. This is required because OCL String types do not natively support any SQL like type operation. On the other hand, OCL does allow us to create and use user defined types. This permits us to create and use the StringUtils.isLike method without violating standards. context LegalAgreement::findByLegalPartyName(aLegalPartyName:String) body findByLegalPartyNameBody: allInstances() -> select( legalAgreement | legalAgreement.legalAgreementParties -> includesAll( legalAgreement.legalAgreementParties -> select( legalAgreementParty | StringUtils.isLike(legalAgreementParty.legalParty.legalPartyName, aLegalPartyName))))
Sorting results requires use of the sortedBy expression. The sortedBy expression allows you to specify by which properties the query results should be ordered. context org::andromda::contracts::LegalAgreement::findAll():Collection(LegalAgreement) body : LegalAgreement.allInstances() -> sortedBy(documentTitle) -> sortedBy(expiredDate)