dr. philip cannata 1 mgr semantic data management

15
Dr. Philip Cannata emp_project deadline dept deptno dnam e loc project pnum pnam e em p job sal com m 0..1 0..* 0..1 0..* 0..* 0..* 0..* 0..* 0..1 0..1 0..1 0..1 person nam e ss_num custom er contact_info mgr Semantic Data Management

Upload: clarence-berry

Post on 05-Jan-2016

233 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 1

emp_projectdeadline

deptdeptnodnameloc

projectpnumpname

empjobsalcomm

0..10..* 0..10..*

0..*

0..*

0..*

0..*

0..1

0..1

0..1

0..1

personnamess_num

customercontact_info

mgr

Semantic Data Management

Page 2: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 2

emp_projectdeadline

deptdeptnodnameloc

projectpnumpname

empjobsalcomm

0..10..* 0..10..*

0..*

0..*

0..*

0..*

0..1

0..1

0..1

0..1

personnamess_num

customercontact_info

CLASS person( ss_num: INTEGER, REQUIRED; name: STRING; );

SUBCLASS emp OF person( job : STRING; mgr : emp, SV, INVERSE IS employees; sal : INTEGER; comm : INTEGER; dept : dept, SV, INVERSE IS employees;);

CLASS dept ( deptno : INTEGER, REQUIRED; dname : STRING; loc : STRING; employees : emp, MV, INVERSE IS dept;);mgr

Semantic Data Management

Page 3: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 3

CLASS person( ss_num: INTEGER, REQUIRED;

name: STRING;);

SUBCLASS emp "Employees of a company" OF person(

job : STRING; mgr : emp, SV, INVERSE IS employees; employees : emp, MV, INVERSE IS mgr;

sal : INTEGER;comm : INTEGER;dept : department, SV, INVERSE IS employees;

);

INSERT emp ( ss_num:= 7369 , name := "SMITH" , job := "CLERK" , sal := 800 );INSERT emp ( ss_num:= 7499 , name := "ALLEN" , job := "SALESMAN" , sal := 1600 , comm := 300 );INSERT emp ( ss_num:= 7521 , name := "WARD" , job := "SALESMAN" , sal := 1250 , comm := 500 );INSERT emp ( ss_num:= 7566 , name := "JONES" , job := "MANAGER" , sal := 2975 );INSERT emp ( ss_num:= 7654 , name := "MARTIN" , job := "SALESMAN" , sal := 1250 , comm := 1400 );INSERT emp ( ss_num:= 7698 , name := "BLAKE" , job := "MANAGER" , sal := 2850 );INSERT emp ( ss_num:= 7782 , name := "CLARK" , job := "MANAGER" , sal := 2450 );INSERT emp ( ss_num:= 7788 , name := "SCOTT" , job := "ANALYST" , sal := 3000 );INSERT emp ( ss_num:= 7839 , name := "KING" , job := "PRESIDENT" , sal := 5000 );INSERT emp ( ss_num:= 7844 , name := "TURNER" , job := "SALESMAN" , sal := 1500 );INSERT emp ( ss_num:= 7876 , name := "ADAMS" , job := "CLERK" , sal := 1100 );INSERT emp ( ss_num:= 7900 , name := "JAMES" , job := "CLERK" , sal := 950 );INSERT emp ( ss_num:= 7902 , name := "FORD" , job := "ANALYST" , sal := 3000 );INSERT emp ( ss_num:= 7934 , name := "MILLER" , job := "CLERK" , sal := 1300 );

Page 4: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 4

CLASS department "Departments of a company"

(

deptno : INTEGER, REQUIRED;

dname : STRING;

loc : STRING;

employees : emp, MV, INVERSE IS dept;

);

INSERT department ( deptno := 10 , dname := "ACCOUNTING" , loc := "NEW YORK" );

INSERT department ( deptno := 20 , dname := "RESEARCH" , loc := "DALLAS" );

INSERT department ( deptno := 30 , dname := "SALES" , loc := "CHICAGO" );

INSERT department ( deptno := 40 , dname := "OPERATIONS" , loc := "BOSTON" );

Page 5: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 5

MODIFY emp ( dept := department WITH (deptno = 20) ) WHERE ss_num = 7369 ;

MODIFY emp ( dept := department WITH (deptno = 30) ) WHERE ss_num = 7499 ;

MODIFY emp ( dept := department WITH (deptno = 30) ) WHERE ss_num = 7521 ;

MODIFY emp ( dept := department WITH (deptno = 20) ) WHERE ss_num = 7566 ;

MODIFY emp ( dept := department WITH (deptno = 30) ) WHERE ss_num = 7654 ;

MODIFY emp ( dept := department WITH (deptno = 30) ) WHERE ss_num = 7698 ;

MODIFY emp ( dept := department WITH (deptno = 10) ) WHERE ss_num = 7782 ;

MODIFY emp ( dept := department WITH (deptno = 20) ) WHERE ss_num = 7788 ;

MODIFY emp ( dept := department WITH (deptno = 10) ) WHERE ss_num = 7839 ;

MODIFY emp ( dept := department WITH (deptno = 30) ) WHERE ss_num = 7844 ;

MODIFY emp ( dept := department WITH (deptno = 20) ) WHERE ss_num = 7876 ;

MODIFY emp ( dept := department WITH (deptno = 30) ) WHERE ss_num = 7900 ;

MODIFY emp ( dept := department WITH (deptno = 20) ) WHERE ss_num = 7902 ;

MODIFY emp ( dept := department WITH (deptno = 10) ) WHERE ss_num = 7934 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7902) ) WHERE ss_num = 7369 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7698) ) WHERE ss_num = 7499 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7698) ) WHERE ss_num = 7521 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7839) ) WHERE ss_num = 7566 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7698) ) WHERE ss_num = 7654 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7839) ) WHERE ss_num = 7698 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7839) ) WHERE ss_num = 7782 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7566) ) WHERE ss_num = 7788 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7698) ) WHERE ss_num = 7844 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7788) ) WHERE ss_num = 7876 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7698) ) WHERE ss_num = 7900 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7566) ) WHERE ss_num = 7902 ;

MODIFY emp ( mgr := emp WITH (ss_num = 7782) ) WHERE ss_num = 7934 ;

Page 6: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 6

cd Nicolette Cannata@pcannata /cygdrive/c/Documents and Settings/Nicolette Cannata/My Documents/pcannata/UT/07 Fall 327e/07 Fall e327/07 Fall e327/Class Notes/20 SIM DB/WDB

$ java -cp "lib\je.jar;." wdb.WDB

WDB Simantic Database Project

Copyright 2006 University of Texas at Austin

DB Name: test DB Path: ./

WDB> source "scott-tiger-Enhanced.txt";

WDB>

Page 7: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 7

WDB> from person retrieve * where true;

WDB> from emp retrieve * where true;

emp_projectdeadline

deptdeptnodnameloc

projectpnumpname

empjobsalcomm

0..10..* 0..10..*

0..*

0..*

0..*

0..*

0..1

0..1

0..1

0..1

personnamess_num

customercontact_info

Page 8: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 8

WDB> from emp retrieve * where true; WDB> from department retrieve * where true;

WDB> from emp retrieve *, * of dept where true;

Page 9: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 9

WDB> from emp retrieve ss_num, name, dname of dept, name of mgr, dname of dept of mgr where true;

emp_projectdeadline

deptdeptnodnameloc

projectpnumpname

empjobsalcomm

0..10..* 0..10..*

0..*

0..*

0..*

0..*

0..1

0..1

0..1

0..1

personnamess_num

customercontact_info

Page 10: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 10

Page 11: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 11

Page 12: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 12

Page 13: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 13

Java Upcasting and Downcasting

Click here for example html or see the “Java Upcasting and Downcasting” link on the class webpage

Click here for example code or see the Test.java link on the class webpage or see the next page.

Page 14: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 14

Java Upcasting and Downcasting – Test.javaclass Animal {

static int value = 100;}

class Cat extends Animal { int value = Animal.value + 1; }

class Dog extends Animal { int value = Animal.value + 2; }

public class Test { public static void main(String[] args) { Cat c = new Cat(); System.out.println(c.value); Dog d = new Dog(); System.out.println(d.value); Animal a = c; System.out.println(a.value); Object o = c; // System.out.println(o.value); a = d; type(c); type(d); type(a); // type(a.value); Dog d2 = (Dog) a; a = c; Dog d3 = (Dog) a; } public static void type(Animal a){ System.out.println("I am a " + a); }}

Page 15: Dr. Philip Cannata 1 mgr Semantic Data Management

Dr. Philip Cannata 15

Java Upcasting and Downcasting – Test.javaclass Animal {

static int value = 100;}

class Cat extends Animal { int value = Animal.value + 1; }

class Dog extends Animal { int value = Animal.value + 2; }

public class Test { public static void main(String[] args) { Cat c = new Cat(); System.out.println(c.value); Dog d = new Dog(); System.out.println(d.value); Animal a = c; System.out.println(a.value); Object o = c; // System.out.println(o.value); a = d; type(c); type(d); type(a); // type(a.value); Dog d2 = (Dog) a; a = c; Dog d3 = (Dog) a; } public static void type(Animal a){ System.out.println("I am a " + a); }}

Textbook Chapter 24

In languages like Java, programmers think they have the benefit of a type system, but in fact many common programming patterns force programmers to employ casts instead. Casts intentionally subvert the type system and leave checking for execution time. This indicates that Java’s evolution is far from complete. In contrast, most of the type problems of Java are not manifest in a language like ML, but its type systems still holds a few (subtler) lurking problems. In short, there is still much to do before we can consider type system design a solved problem. . . .

Types form a very valuable first line of defense against program errors. Of course, a poorly-designed type system can be quite frustrating: Java programming sometimes has this flavor. A powerful type system such as that of ML, however, is a pleasure to use. ML programmers, for instance, claim that programs that type correctly often work correctly within very few development iterations.

Types that have not been subverted (by, for instance, casts in Java) perform several valuable roles:• When type systems detect legitimate program errors, they help reduce the time spent debugging.• Type systems catch errors in code that is not executed by the programmer. This matters because if a programmer constructs a weak test suite, many parts of the system may receive no testing. The system may thus fail after deployment rather than during the testing stage. (Dually, however, passing a type checker makes many programmers construct poorer test suites—a most undesirable and unfortunate consequence!)