1 / 18

Object Query Language ( OQL )

Object Query Language ( OQL ). Mari án Kamenišťák MFF – UK Praha 26.11.2003. Úvod. podobný SQL jazyku založený na ODMG štandarte Architektúra: Nástroje: C, C++, Java, … DB engine: napr. O2 engine & store Interfaces: O2ODBC, O2Cobra,. Z ákladné dotazy (C++).

dragon
Download Presentation

Object Query Language ( OQL )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object Query Language (OQL) Marián Kamenišťák MFF – UK Praha 26.11.2003

  2. Úvod • podobný SQL jazyku • založený na ODMG štandarte • Architektúra: • Nástroje: C, C++, Java, … • DB engine: napr. O2 engine & store • Interfaces: O2ODBC, O2Cobra, ..

  3. Základné dotazy (C++) • class item {String what; double price;}; • class client {String name; Array <item> order; int amount(); };

  4. Základné dotazy • Select distinct e.salary from e in Schema.employees where e.family != nil and e.position = “reporter”; • … where count(e.children) >=1; • … group by … having … • … order by … (vracia pole) • existujú agregačné fcie: min, max, sum, avg

  5. Tvorenie výsledkov • Define MyEmployees as select struct(employee: struct(e.name, position: e.post), salary: e.salary) from e in Company.employees; • element (select e from e in MyEmployees where e.salary>150000);

  6. Množinové operátory • Zjednotenie(+): MyEmployees + YourEmployees • Prienik (*) • Rozdiel (-)

  7. Konverzie • listtoset(Companies[2].clients) • Naopak: select e from e in MyEmployees order by e.name; • z kolekcie kolekcií na plochú kolekciu: flatten(select e.clients from c in Companies); • flatten(list(list(1,2), list(1,2,3))) -> list(1,2,1,2,3) • ‘string’ like ‘%nice_%’

  8. Preddefinované typy kolekcií • Set<T> - mna • set(1,2,5) • Bag<T> - multimna • bag(1,2,2,3,3) • Varray<T> - dynamické pole • List<T> - Varray s metódami pre manipuláciu (insert, delete,..) • list(1,2,2,3); list(3..5) • Ref - perzistentný pointer

  9. Pokročilé OQL • class Person { String name; Date birth; set<ref<Person>> childs inverse parents; set<ref<Person>> parents inverse childs; Person(); //constructor void birth(ref<Person> child); //narodenie d. virtual set<String> activities(); }

  10. OQL • class Employee:Person{ //podtrieda float salary; virtual set<String> activities();//predefinit. }; • Join: • Select p from p in Persons, b in (select a.building from a in Apartments) Where p.name = b.address.street;

  11. OQL – Data manipulation • select struct (me:p.name, address:p.lives_in.building.address; childs: (select struct(name: c.name, address: c.lives_in.building.address) from c in p.children) ) from p in Persons; //adresy detí cez všetky osoby.

  12. OQL Polymorfizmus • napr. mna Persons obsahuje prvky tried Preson, Employee, Student. • Potom sa virtuálna metóda activities() vykoná pre konkrétnu triedu. • Select ((Student)p).grade from p in Persons where “lecture” in p.activities;

  13. OQL • define salary_map as select street, average_salary: avg(select p.e.salary from partition p) from e in Employees group by e.lives_in.building.address.street; //returns Bug<struct {String street; float avg_salary;>};

  14. OQL • define sorted_salary_map as select s from s in salary_map order by s.average_salary List<struct {String street; float avg_salary;} > • sorted_salary_map[2].street;

  15. OQL • define Jakes as select x from Students x where x.name = “Jake”; • define Jake as first(element( select x from Students x where x.name = “Jake”)); • //first, last operators in list

  16. OQL • Prechádzanie štruktúrami: • person.name == person->name //rovnaké • Jake->woman!=nil and Jake->woman->name=Carol • Dereferencie • p1 = p2 je pravda, ak ukazujú na rovnaký objekt • *p1 = *p2 je pravda, ak majú rovnaké hodnoty

  17. OQL - group by • select * from Employees e group by low: e.salary<1000, medium: e.salary>=1000 and e.salary<2000, high: e.salary>=2000; Vytvorí pomenované partition bugy

  18. Literatúra • ODMG OQL user manual 5.0 • feb. 1998

More Related