Contents
PrefaceAbout OQLOQL is a simple language. It looks like SQL. If you know SQL you may read this document and glance over OQL specification from ODMG to know how to write FL OQL query. There are some additions. They are contained in this document at
Addition to OQL Standard 1.2 chapter.
This document describes how to write and how to execute FL OQL queries. Also it contains some additions to ODMG OQL standard 1.2 those may be used at OQL queries. Addition to OQL Standard 1.2Additions to: Additions to 4.11.1.1 Axiom
How to Write FL OQL QueryThis chapter has some examples of FL OQLs. To learn OQL see ODMG OQL specification. To get entityGetting of all entities:
select e from Entity e
e is iterator of collection Entity .
SQL query for this OQL query is:
select e.id0, e.typeid0 from Entity0 e where e.id0 > -1
This OQL query result in List<Entity> .
Each element of the list is obtained via
ObjectManager.getObject(Integer primaryKey,
Getting of entities with id less than 100:
select e from Entity e where e < 100
SQL for this:
select e.id0, e.typeid0 from Entity0 e where e.id0 < 100 and e.id0 > -1
So when iterator of Entity collection is part of
arithmetic or relational operation then it is interpreted as id.
Class attributes
select t.name from Type t where t.attrInt < $1
Results in List<String> .
"$1 " is bind argument. Its value you may set
before execution of the query.
select t, t.attrInt from Type t where t.attrInt < $1
Results in List<List<Type, Integer>> .
select t.name from Type t where t.name like $1
Results in List<String> .
select t from Type t where t in set(101,202,303)
Results in List<Type> . SQL for this:
select t.id0, t.typeid0 from Type0 t where t.id0 in (101,202,303) and t.id0 > -1
Class associationsAssociation with zero or one multiplicity
select t.role from Type t
Results in List<Role> .
select r from Type t, Role r where t.role = r
Result is the same.
select t, r
Results in from Type t, Role r where t.name = $1 and t.attrInt = $2 and r.name = $3 List<List<Type, Role>> .
Association with zero or more multiplicity
select t,rl from Type t, t.roleList rl
Results in List<List<Type, Role>> .
Result is Cartesian product t*rl .
select rl from Type t, t.roleList rl where rl.name != nil
Results in List<Role> : Role objects those are
associated with a Type object and have name attribute of
not null.
SQL for this OQL query is:
select rl.id0, rl.typeid0
from Type0 t, Role0 rl, Type_rolel92 al_0 where rl.name is not null and
t.id0 = al_0.id0 and al_0.roleList0 = rl.id0 and rl.id0 > -1
To get list attribute elements as list:
select t.roleList from Type t where t.roleList != nil
For this query two SQLs are executed:
select t.id0, t.rolelist_194
and
from Type0 t where t.rolelist_194 = 'N'
select al_1.id0, al_0.id0, al_0.typeid0
from Type_rolel92 al_1, RoleList0 al_0 where al_1.rolelist0 = al_0.id0 and al_1.id0 in (87,102,203,413) Aggregation operations
select count(e),min(e),max(e) from Entity e
is translated to
select count(e.id0),min(e.id0),max(e.id0) from Entity0 e where e.id0 > -1
How to Execute FL OQL QueryTo execute OQL query it is needed to create instance of OQLInterpreter
public OQLInterpreter(com.novosoft.fl.ObjectManager objectManager, java.lang.String mappingFileName)
or public OQLInterpreter(com.novosoft.fl.ObjectManager objectManager, java.io.InputStream mappingFile)
Mapping file is property file. To create mapping file FL packaging (since fl4_2_2-jdk1_2.zip) has createMapping.cmd scenario. This cmd-file builds mapping on UML model and atr-file. ExecutingThere some ways to execute OQL query. Among them there is a possibility to create a prepared statement. Simple wayOne of Example. Let we want to execute
select e from Entity e where e < $1
OQL query and set $1 to Integer of 100:
import ru.novosoft.uml.oql.OQLInterpreter; Prepared statement usageOQLQueryOQLQuery OQLInterpreter.createOQLQuery(java.lang.String oqlQuery, java.sql.Connection connection) A Example of
import ru.novosoft.uml.oql.OQLInterpreter; import ru.novosoft.uml.oql.OQLQuery; import java.sql.Connection; Supported OQL QueriesSupported features are described in Grammar terms. (see Grammar chapter in ODMG OQL specification) AxiomAll including:
BasicAll. Note: a bind argument has name with prefix of dollar sign " $ " and postfix of a positive integer.
Simple ExpressionAll excepting:
ComparisonAll. Boolean ExpressionAll. ConstructorSupported:
AccessorSupported:
Collection ExpressionAll excepting:
Select ExpressionSupported:
projection_attributes ::= projection {, projection} proiection_attributes ::= * projection ::= identifier dot attribute_name variable_declaration ::= query as identifier sort_criterion ::= query [ordering] ordering ::= asc ordering ::= desc Set ExpressionNone. ConversionSupported:
FL and OQLFL TransactionsOQL system does not use FL transactions at all. So you are free to decide must be or not OQL query execution within FL transaction. OQL System Responsibilities
|