Copyright © Ellis Cohen

Slides:



Advertisements
Similar presentations
HTML FORMS
Advertisements

Realtime Equipment Database F.R.E.D. stands for Fastline’s Realtime Equipment Database. F.R.E.D. will allow you to list all your inventory online. F.R.E.D.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Concepts of Database Management Sixth Edition
Management Information Systems MS Access 2003 By: Mr. Imdadullah Lecturer, Department of M.I.S. College of Business Administration, KSU.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
Database Applications – Microsoft Access Lesson 2 Modifying a Table and Creating a Form 45 slides in presentation Accessibility check 9/14.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Web Application Architecture and Communication. Displaying a Web page in a Browser
Database Programming in Java Corresponds with Chapter 32, 33.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Copyright  Oracle Corporation, All rights reserved. 5 CMIS Powell Oracle Designer: Design Editor and Building the Database and Table API CMIS.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen M:N Relationships & Bridge Classes These.
Your Name Here See Page Notes for Info about Hyperlinks.
Summary Data Modeling SDLC What is Data Modeling Application Audience and Services Entities Attributes Relationships Entity Relationship Diagrams Conceptual,Logical.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
PHP meets MySQL.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Text 1 July, 2010 DCMS: Training Manual Interface and Master Data Management.
Management Information Systems MS Access MS Access is an application software that facilitates us to create Database Management Systems (DBMS)
1 OPOL Training (OrderPro Online) Prepared by Christina Van Metre Independent Educational Consultant CTO, Business Development Team © Training Version.
In the next step you will enter some data records into the table. This can be done easily using the ‘Data Browser’. The data browser can be accessed via.
Training Guide for Inzalo SOP Users. This guide has been prepared to demonstrate the use of the Inzalo Intranet based SOP applications. The scope of this.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen :1 Relationships These slides are licensed.
Introduction to Databases Trisha Cummings. What is a database? A database is a tool for collecting and organizing information. Databases can store information.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
M1G Introduction to Database Development 2. Creating a Database.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
ITCS373: Internet Technology Lecture 5: More HTML.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Maintaining Session State in the Data.
CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Conditions & Roles These slides are licensed.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Maintaining Session State in the Data.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Implementing The Middle Tier These slides.
Table of Contents TopicSlide Administrator Login 2 Administrator Navigations 3 Managing AlternativeDr.com Blogs 4 Managing Dr. Lloyd May Blogs 5 Managing.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Subqueries These slides are licensed under.
IST 220 – Intro to Databases Lecture 2 Touring Microsoft Access.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Using Data Structures in Embedded Programs.
Page 1 of 42 To the ETS – Create Client Account & Maintenance Online Training Course Individual accounts (called a Client Account) are subsets of the Site.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
CS223: Software Engineering Lecture 13: Software Architecture.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Roles & Constraints These slides are licensed.
Web Application Design. Data –What data is available? –How do we store it or how is it stored in the DB? Schema Data types Etc. –Where is the data?
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Live. learn. work. play Superior Avenue Suite 310 Cleveland Ohio Tel: Fax:
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Dynamic Website Design for Temple Beth-El of Ithaca, NY CS 501 Project – Final Presentation May 4, 2006 Presented By: Peter Babinski, Christopher Benedict,
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Use Case Diagrams A Detailed Description. Use Case Diagrams Use case diagrams describe relationships between users and use cases A use case is a (usually.
Creating Oracle Business Intelligence Interactive Dashboards
Developer 2000 CSE 4504/6504 Lab.
Summary Data Modeling SDLC What is Data Modeling
Presentation transcript:

Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen 2002-2008 Introduction to Designing & Programming Database Applications These slides are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. For more information on how you may use them, please see http://www.openlineconsult.com/db

Overview of Lecture User Operations in Database Applications Job Board Database Design Identifying User Operations Queries Following Actions Operation Parameters User Operations and Conceptual ER Models Database Application Programming & Design © Ellis Cohen 2001-2008

User Operations in Database Application © Ellis Cohen 2001-2008

Client/Server Architecture SQL Statements are passed through API & protocol User DB Application API Database Server DB Application Client DB Client Implements DB Operations Client-Side Server-Side © Ellis Cohen 2001-2008

Web-Based 3-Tier Architecture Handles overall DB mgt, formatting & page navigation DB Application API Database Server User Web Browser Web or Application Server Implements User Operations Implements DB Operations Presentation Tier Middle Tier Data Tier (DB) Client-Side (DB) Server-Side © Ellis Cohen 2001-2008

Invoking User Operations Typically, in a web browser A user makes some choices Fills in data entry fields Then CLICKS a BUTTON The button click submits a request to the web server, which, then invokes a user operation in the middle tier provides the choices the user made, and the data the user filled in as input parameters to the user operation © Ellis Cohen 2001-2008

User Query Operation Invokes operation Provides parameters © Ellis Cohen 2001-2008

User Operation Parameters User operations have parameters ShowMatchingRestaurants( :cuisine, :loc, :price, :orderBy ) The user operation parameters (named starting with a :colon) are provided from values filled in or chosen by the user © Ellis Cohen 2001-2008

ShowMatchingRestaurants Operation Name of the user operation ShowMatchingRestaurants :cuisine = American :loc = Allston/Brighton :price = 12.00 :orderBy = restName Parameter values passed to the operation © Ellis Cohen 2001-2008

User Query Results © Ellis Cohen 2001-2008

User Query Operation Information Flow DB Query Database Server DB Application API Query Results User Query Web Browser Web Server Results Page © Ellis Cohen 2001-2008

Restaurants Table Restaurants restName – restaurant name To satisfy the previous query, these are the attributes of the Restaurants Table, which need to be stored in the database Restaurants restName – restaurant name restAddr – its address cuisine – primary type of cuisine loc – neighborhood it is in price – typical price for a meal rating – restaurant rating (0-5) Using the choices the user made, the middle-tier code generates a SQL command to produce the results © Ellis Cohen 2001-2008

User & DB Query Operations User Query Operation: ShowMatchingRestaurants :cuisine = American' :loc = Allston/Brighton :price = 12.00 :orderBy = restName DB Query Operation: SELECT restName, restAddr FROM Restaurants WHERE cuisine = 'American' AND loc = 'Allston/Brighton' AND price < 12.00 ORDER BY restName © Ellis Cohen 2001-2008

User Operations Just as it is useful to categorize a DB Operation as a DB Query DB Action It is also useful to categorize a User Operation as a User Query just displays information User Action modifies the application state and/or the data in the database © Ellis Cohen 2001-2008

User/Database Operations User Query DB Query User enters data, makes choices, clicks a button Note: A few User Actions might only do DB Queries or not access the DB at all User Action DB Action User Operations DB Operations DB Application API Database Server Web Browser Web or Application Server Presentation Tier Middle Tier Data Tier © Ellis Cohen 2001-2008

User Action: Register © Ellis Cohen 2001-2008

User Action Information Flow DB Action Database Server DB Application API Ack User Action Web Browser Web Server Ack Page Instead of just showing an Ack Page, the middle tier often navigates automatically to some other useful page © Ellis Cohen 2001-2008

Job Board Database Design © Ellis Cohen 2001-2008

Job Board Application Requirements An Online Job Board Application allows job candidates to provide personal information information about the job they are seeking, including the industry and title they are looking for, and the location they would prefer to work (let's assume just one location to keep things simple) a job history, each entry of which describes a job they had, including the company they worked for, and the dates they worked for them. Company representatives post information about their company, (including the single industry they are in) and can post open jobs (and remove them when they are filled). Each open job posting includes the location and title of the job, as well as other information. © Ellis Cohen 2001-2008

Job Board User Roles Different users of the system play different roles. The two roles we've discussed are Job Candidate Company Representative There are other roles as well (which we won't discuss now) Administrator (too complicated) UnknownUser (someone who is not logged in, but perhaps can still get some job board information) © Ellis Cohen 2001-2008

Job Board Application: Detailed ER Diagram job history includes Candidate JobEntry candid name descr industryWanted titleWanted locationWanted entryid jobno title location startDate endDate details occurred at open at JobPosting Company postid title location descr postdate compid compname industry descr status © Ellis Cohen 2001-2008

Possible Entity Classes Candidate someone looking for a job Company a company that people work for Job Posting description of an open job Job Entry a description of a single job that a candidate had Industry description of an industry Company Representative Job History a candidate's job history We definitely need these classes Should we add these classes or not? Why? © Ellis Cohen 2001-2008

Adding Industry Candidate JobEntry Industry Company JobPosting job history includes Candidate JobEntry candid name descr titleWanted locationWanted entryid jobno title location startDate endDate details occurred at wants job in has Industry Company industrynam compid compname descr status open at JobPosting postid title location descr postdate © Ellis Cohen 2001-2008

Entity Classes With Only Primary Key Attributes If we did not have an Industry class, both Company and Candidate would have industry attributes the industry the company is in the industry the candidate wants to work in Should we instead make Industry an entity class? YES: Industry meets the criteria of substance & extensibility & possibly association NO: Industry has no other attributes now, and in the context of this application, it is not clear that Industry would be extended. Current engineering practice puts less emphasis on designing for extensibility. So keep industry as an attribute for now, and refactor the design later if needed. IMPORTANT NOTE: We will revisit this issue when we discuss the use of Referential Integrity and Check Constraints in the Relational Model © Ellis Cohen 2001-2008

Roles vs Entity Classes Company Representative represents a role that a user can play. But does that mean it should automatically be used as an entity class? Perhaps, but not necessarily: First of all, there are no attributes we need to keep about Company representatives, except their login ID. All representatives of the same company could share a single company login ID. Nothing in our requirements suggests we need to distinguish between the various representatives of a company. has Company Company Representative © Ellis Cohen 2001-2008

Entity Classes Without Attributes in 1-1 Relationships has contains Candidate Job History Job Entry candno The relationship between Candidate & Job History is a 1-1 relationship, with two interesting characteristics: Every Job History has an associated Candidate While a Job History has a collection of Job Entries, it has no attributes; it doesn't really need to have its own primary key, since whatever uniquely identifies a job candidate (candno) also uniquely identifies that candidate's job history. So there really is no reason to keep Job History. Replace the model above by has Candidate Job Entry candno © Ellis Cohen 2001-2008

Identifying User Operations (a simplified approach to Use Cases) © Ellis Cohen 2001-2008

Job Board Requirements: Job Candidates An Online Job Board Application allows job candidates to provide personal information information about the job they are seeking, including the industry and title they are looking for, and the location where they would prefer to work (let's assume just one to keep things simple) a job history, each entry of which describes a job they had, including the company they worked for, and the dates they worked for them. © Ellis Cohen 2001-2008

Login Page User operations result from user interactions login id password LOGIN Not Yet Registered? Register Corresponds to the Login user action © Ellis Cohen 2001-2008

User Operation Parameters User operations have parameters Login( :userid, :pwd ) -- this user action logs in the user and -- also remembers the user's userid The parameters are provided from values filled in or chosen by the user © Ellis Cohen 2001-2008

View/Edit Personal Info Corresponds to the GetJobHistory user query Home Page Welcome Joe Candidate View/Edit Personal Info View/Edit Job Desired View/Edit Job History Corresponds to the GetJobHistory user query © Ellis Cohen 2001-2008

If Edit is pressed, what's the operation? Is it a Query or an Action? My Jobs Page HOME Delete Edit 1941-1947 GE Delete Edit 1948-1984 Smith & Barney Delete Edit 1984-2001 Smith & Wesson Delete Edit 2001-2006 Wesson Oil New Job Entry If Edit is pressed, what's the operation? Is it a Query or an Action? © Ellis Cohen 2001-2008

Job Entry Page What operation corresponds to the Update button? Add Company Company Smith & Barney Location New York, NY Start 1948 End 1984 Description Started as Jr Accountant. Eventually became Chief Financial Officer. Update What operation corresponds to the Update button? © Ellis Cohen 2001-2008

Identifying Queries & Actions We have already identified Queries GetJobHistory GetJobEntry Actions Login UpdateJobEntry What additional user query and action operations are needed just to support viewing and modifying candidate information? © Ellis Cohen 2001-2008

Candidate User Operations Queries GetPersonalInfo GetJobDesired GetJobHistory GetJobEntry Actions Login Logout RegisterCandidate RemoveCandidate UpdatePersonalInfo UpdateJobDesired AddJobEntry UpdateJobEntry DeleteJobEntry AddCompany Note: I use Get in the operation name to imply that the information will be editable by the user Are there other queries which would be useful for job candidates? © Ellis Cohen 2001-2008

Additional Candidate User Queries Queries (continued) ShowCompaniesWithPostings ShowCompanyInfo ShowPosting ShowMatchingPostings ShowPostingsThatMatchMyDesires etc. Note: I use Show in the operation name to imply that the information will NOT be editable by the user © Ellis Cohen 2001-2008

Job Board Requirements: Company Representatives Company representatives post information about their company, (including the industry they are in) and can post open jobs (and remove them when they are filled). Each open job posting includes the location and title of the job, as well as other information. What user query and action operations are needed just to support viewing and modifying company representative information? © Ellis Cohen 2001-2008

Representative User Operations Queries GetCompanyInfo GetPostings GetJobPosting Actions Login Logout RegisterCompany RemoveCompany UpdateCompanyInfo AddJobPosting UpdateJobPosting DeleteJobPosting Are there other actions or (especially) queries that are not required, but are likely to be desired by company reps? © Ellis Cohen 2001-2008

Additional Representative User Queries Queries (continued) Show CandidatesMatchingPosting ShowCandidateInfo ShowJobEntry ShowCompaniesWithPostings ShowCompanyInfo ShowPosting ShowMatchingPostings etc. Might as well allow a company representative to show things a job candidate can. After all, they can always register as a job candidate and get that information anyway! © Ellis Cohen 2001-2008

Queries following Actions © Ellis Cohen 2001-2008

Interactive User Action Execution (Get user input from browser and provide as parameters for user action) Invoke DB actions to update the DB as necessary Either Choose a completed acknowledgement page or some other generic useful page to display to the user, or Automatically choose a User Query to be executed which will determine the contents of the page to be shown to the user © Ellis Cohen 2001-2008

Action Followup Queries Actions Login Logout RegisterCandidate RemoveCandidate UpdatePersonal Info UpdateJobDesired AddJobEntry UpdateJobEntry DeleteJobEntry AddCompany For each action, what would you choose as the followup query? © Ellis Cohen 2001-2008

User Action Followups Login: Home Logout: Login RegisterCandidate: Home RemoveCandidate: Login UpdatePersonalInfo: Home UpdateJobDesired: Home AddJobEntry: GetJobHistory UpdateJobEntry: GetJobHistory DeleteJobEntry: GetJobHistory AddCompany: GetJobEntry © Ellis Cohen 2001-2008

Operation Parameters © Ellis Cohen 2001-2008

Hidden Parameters Not all parameters to an operation are chosen or entered by the user Some values are hidden on the page (placed there by the application when the page is constructed) Hidden parameters can be passed as values to the user © Ellis Cohen 2001-2008

What happen when Delete is pressed? Buttons & Parameters HOME Delete Edit 1941-1947 GE Delete Edit 1948-1984 Smith & Barney Delete Edit 1984-2001 Smith & Wesson Delete Edit 2001-2006 Wesson Oil New Job Entry What happen when Delete is pressed? © Ellis Cohen 2001-2008

Hidden Values Clicking on any Delete button invokes the User Action Operation DeleteJobEntry( :jobno ) Clicking the 2nd Delete button calls DeleteJobEntry( 2 ) indicating that the user's 2nd job entry should be deleted When GetJobEntryHistory passed the HTML for My Job Page to the user, it associated 2 (in the HTML) with the 2nd Delete button. The 2 is hidden from the user, but when the button is pressed, the HTML code uses the associated hidden value as the parameters. © Ellis Cohen 2001-2008

Identifying the Current User The middle tier application can retain information about each user it is interacting with. When a user logs in, the user's login id is remembered by the middle tier application, and is available to the implementation of every user operation! Because a user's Job Entry can only be updated by that user, the implementation of DeleteJobEntry can simply get the remembered id of the current user and use that to determine whose job entry to delete © Ellis Cohen 2001-2008

The user clicks the Edit button next to the 2nd entry My Jobs Page HOME Delete Edit 1941-1947 GE Delete Edit 1948-1984 Smith & Barney Delete Edit 1984-2001 Smith & Wesson Delete Edit 2001-2006 Wesson Oil New Job Entry The user clicks the Edit button next to the 2nd entry © Ellis Cohen 2001-2008

Job Entry Page Company Smith & Barney Location New York, NY Start 1948 Add Company Company Smith & Barney Location New York, NY Start 1948 End 1984 Description Started as Jr Accountant. Eventually became Chief Financial Officer. Update What are the parameters passed to UpdateJobEnty, and what are their values? © Ellis Cohen 2001-2008

UpdateJobEntry Parameters UpdateJobEntry( :jobno, :compid, :loc, :startdate, :enddate, :descr ) :jobno = 2 :compid = 61 (the company id for Smith & Barney) :loc = New York, NY :startdate = 1948 :enddate = 1984 :descr = Started as Jr Accountant. Eventually became Chief Financial Officer. The code on the HTML page directed it where to get the parameters when UPDATE was pressed, including getting 2 from a value hidden on the page. How was 61 passed for Smith & Barney? © Ellis Cohen 2001-2008

Constructing GetJobEntry The code of GetJobEntry builds the HTML for the Job Entry page In addition to showing the company name, loc, startdate, enddate & descr, it also hides the # of the job entry (e.g. 2) on the page builds a pulldown list of every known company name (shown) their corresponding company id (which is hidden – e.g. 61 for 'Smith & Barney') © Ellis Cohen 2001-2008

Some Candidate User Operations GetJobHistory RegisterCandidate RemoveCandidate AddCompany What are the parameters for each of these? © Ellis Cohen 2001-2008

Operations with Parameters GetJobHistory – no parameters, if only a candidate get their own job history, so assumes the current user GetJobHistory( :userid ) – if can be used either by a Job Candidate or a Company Representative (to get the job history of an arbitrary employee) RegisterCandidate( :userid, :pwd, :name, :descr ) RemoveCandidate – no parameters, only a user can remove themselves, so assumes the current user AddCompany( :compname, :industry, :descr ) – don't provide the id, the implementation will automatically create a new id © Ellis Cohen 2001-2008

Obtaining Parameters User Operations do NOT necessarily get all their inputs from the parameters passed to them when they are invoked In a web-based, popup windows, (also known as modal dialogue windows) can request additional info In a text-based system, the user can be prompted for additional info Web Services can make requests of their clients to obtain additional info To simplify examples, assignments & testing in this course, we will assume/require that operations get ALL of their inputs from the parameters passed to them when they are initially invoked! © Ellis Cohen 2001-2008

User Operations and Conceptual ER Models © Ellis Cohen 2001-2008

Conceptual ER Models & User Operations Represent the data that needs to be persisted in the database User Operations Use the data that is persisted (represented both by entity classes and relationships) Queries access the data Actions additionally update some of the data © Ellis Cohen 2001-2008

Relationships & Instances works for Employee Dept Relationships correspond to links between instances They are queried to find which instances are linked together They are modified to add, delete or update a link 7499 ALLEN 1600 300 7654 MARTIN 1250 1400 10 SALES 7844 TURNER 1500 7698 BLAKE 2850 30 ACCOUNTING 7986 STERN 1500 Entity classes & relationships reflect data which is persisted in the database to answer queries & perform actions. © Ellis Cohen 2001-2008

Using the Conceptual Model Entity classes and relationships reflect information that must be persistently retained in the database To check if the conceptual model is complete Consider various queries and actions See if any other entity classes and relationships are needed to answer the query or perform the action Don't include entity classes or relationships unless they're needed to implement the required queries and actions © Ellis Cohen 2001-2008

Job Board Application: Easy Crow Magnum Diagram job history includes Candidate JobEntry candid name descr industryWanted titleWanted locationWanted entryid jobno title location startDate endDate details occurred at open at JobPosting Company postid title location descr postdate compid compname industry descr status © Ellis Cohen 2001-2008

Queries Access Relationships & Entities Suppose a logged in company rep invokes the User Query: Get Postings (i.e. show me the postings for our company, e.g. company 3042) Which relationships and entity classes in the DB must be used to answer the query? JobPosting NO access to Company needed! postid title location desc Company 447 Clerk NY … compid compname … 448 VP Sales Boston … 3042 OM Mfg … 449 Artist SF … 1 2 To get displayable info on each posting To find out which job posting are posted by our company © Ellis Cohen 2001-2008

Queries Access Data Model Suppose a logged in company rep invokes the User Query: Get Postings Which relationships and entity classes in the data model need to be accessed? job history includes Candidate JobEntry occurred at 1 2 open at JobPosting Company postid title location descr postdate To find out which job posting are posted by our company compid compname industry descr status To get displayable info on each posting © Ellis Cohen 2001-2008

Data Model Access Exercise Suppose a candidate logs in and invokes the User Action: Show Companies With Postings What information (relationships & entity classes) represented by the DB model needs to be accessed? job history includes Candidate JobEntry candid name descr industryWanted titleWanted locationWanted entryid jobno title location startDate endDate details occurred at open at JobPosting Company postid title location descr postdate compid compname industry descr status © Ellis Cohen 2001-2008

Data Model Access Answer Suppose a candidate logs in and invokes the User Action: Show Companies With Postings job history includes Candidate JobEntry To find out which companies have postings occurred at 1 open at JobPosting Company 2 postid title location descr postdate compid compname industry descr status But we don't need to know anything specifically about the job postings themselves! To get displayable info on each company © Ellis Cohen 2001-2008

Actions Access/Update Data Model Suppose a candidate logs in and invokes the User Action: Add Job Entry What information represented by the DB model needs to be accessed/updated? To associate that job entry with the candidate 2 job history includes To add a new job entry Candidate JobEntry 1 To associate the job entry with the company worked at for that job entry 4 occurred at open at JobPosting Company To check whether the company is in the DB 3 © Ellis Cohen 2001-2008

Complex Data Model Exercise Suppose a candidate logs in and invokes the User Action: Show Postings that Match My Desires What information represented by the DB model needs to be accessed? job history includes Candidate JobEntry occurred at open at JobPosting Company © Ellis Cohen 2001-2008

Queries Can Access Unrelated Data Suppose a candidate logs in and invokes the User Query: Show Postings that Match My Desires job history includes Candidate JobEntry To determine the desires of that candidate 1 occurred at open at 4 JobPosting Company 2 3 To find which of those postings match the desired location and job title To find the companies that match the desired industry & get company name To find job postings at those companies © Ellis Cohen 2001-2008

Database Application Programming & Design © Ellis Cohen 2001-2008

Embedded SQL Integration of SQL with a general purpose programming language – e.g. PL/SQL Allows complex combinations of database operations to be specified BEGIN INSERT INTO ExEmps SELECT * FROM Emps WHERE termdate IS NOT NULL; DELETE FROM Emps WHERE termdate IS NOT NULL; END; Also provides support for conditionals, iteration, exceptions, procedures, functions, packages, triggers, etc. This is a good example of why transactions are used. We don't want a crash to allow the insert to be done without the delete. What does this do? © Ellis Cohen 2001-2008

Client-side Execution Model PL with embedded SQL Compile (Oracle) Database Server Executable API Library or an interpreter could be used DB Client-side DB Server-side © Ellis Cohen 2001-2008

Embedded SQL Procedures Suppose that when an employee is terminated, that employee's termdate attribute is set to the termination date. Once a week, all the terminated employees are moved from the Emps table to the ExEmps table. It would be useful to define a procedure that implements the move. © Ellis Cohen 2001-2008

Defining Stored DB Operations with Embedded SQL DB operations can be defined and stored at the database server  can be much more efficient Stored DB Operations: Stored Procedures Stored Functions PROCEDURE MoveTerminatedEmployees IS BEGIN INSERT INTO ExEmps SELECT * FROM Emps WHERE termdate IS NOT NULL; DELETE FROM Emps WHERE termdate IS NOT NULL; END; © Ellis Cohen 2001-2008

Database Server Architecture API/Protocol includes request to execute a Stored DB Operation Embedded SQL Engine Executable API Library Database Server Core SQL Database Engine Implements DB operations Implements core DB operations (i.e. SQL commands) DB Client-side DB Server-side © Ellis Cohen 2001-2008

Database Operations: Queries & Action Core DB Operations (i.e. SQL) Stored DB Operations Queries SQL Queries Stored DB Functions Actions SQL Insert/Update/Delete SQL DDL (e.g. create table) SQL DCL (e.g. grant access) Stored DB Procedures © Ellis Cohen 2001-2008

Web-Based 3-Tier Architecture Handles complex queries, updates & integrity maintenance Handles overall DB mgt, formatting & page navigation Stored DB Operations DB Application API Database Server Web Browser Web or Application Server Implements User Operations Implements DB Operations Presentation Tier Middle Tier Data Tier © Ellis Cohen 2001-2008

Database Application Design What kinds of user operations are required and by whom? What functionality should be placed in the middle tier vs. the data tier? How should pre-, post- and output-conditions be enforced? Core and Stored DB Operations User Operations User enters data, makes choices, clicks a button User Query DB Query User Action DB Action Presentation Tier Middle Tier Data Tier © Ellis Cohen 2001-2008