0% found this document useful (0 votes)
6 views

week7_com206

The document outlines the course content for a database systems class, detailing the topics covered each week, including application developments, indexing, big data, and data analytics. It discusses the architecture of application programs, emphasizing the role of front-end, middle layer, and back-end components, as well as the evolution of application architecture from mainframe to web and smartphone eras. Additionally, it covers various technologies and languages used for server-side scripting, including Java Servlets, JSP, PHP, and JavaScript, highlighting their roles in web application development.

Uploaded by

ENES
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

week7_com206

The document outlines the course content for a database systems class, detailing the topics covered each week, including application developments, indexing, big data, and data analytics. It discusses the architecture of application programs, emphasizing the role of front-end, middle layer, and back-end components, as well as the evolution of application architecture from mainframe to web and smartphone eras. Additionally, it covers various technologies and languages used for server-side scripting, including Java Servlets, JSP, PHP, and JavaScript, highlighting their roles in web application development.

Uploaded by

ENES
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Week 7: Application Developments

Database System Concepts, 7th Ed.


©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Course Content (Subject to Change)

Week #1 Introduction to Data Management


and File Structures
Week #2 Storage units and their physical
characteristics (DSC, Ch-12)
Week #3 Introduction to database systems:
E/R Modeling (DSC, Ch1)
Week #4 Introduction to the Relational Model
(DSC, Ch2)
Week #5 Data Storage and Structures (DSC,
Ch-13)
Week #6 Complex Data Types (DSC, Ch-8)
Week #7 Application Developments (DSC Ch-
9)
Week #8 Indexing and B Trees Part 1 (DSC,
Ch-14)

2
Database System Concepts - 7th Edition 8.2 ©Silberschatz, Korth and Sudarshan
Course Content (Subject to Change)

Week #9 Indexing and B Trees Part 2 (DSC,


Ch-14)
Week #10 Big Data (DSC, Ch-10)
Week #11 Data Analytics (DSC, Ch-11)
Week #12 Database and System Architectures
(DSC, Ch-20)
Week #13 Parallel and Distributed Storage
(DSC, Ch-21)
Week #14 Advanced Indexing Techniques
(DSC, Ch-24)
Week #XX Blockhain Databases (DSC, Ch-26)

3
Database System Concepts - 7th Edition 8.3 ©Silberschatz, Korth and Sudarshan
Application Programs and User Interfaces

 The most common way in which users interact with databases is


through an application program that provides a user interface at the front
end and interfaces with a database at the back end.
 An application program acts as the intermediary between users and the
database
 Applications split into
 front-end
 middle layer: contains “business logic,”
 Backend: communicates with a database
 Front-end: user interface
 Forms
 Graphical user interfaces
 Many interfaces are Web-based

Database System Concepts - 7th Edition 8.5 ©Silberschatz, Korth and Sudarshan
Application Architecture Evolution
 Three distinct era’s of application architecture
 Mainframe (1960’s and 70’s)
 Personal computer era (1980’s) The HTML standard is
 Web era (mid 1990’s onwards) independent of the
operating system or
 Web and Smartphone era (2010 onwards)
browser. No installation

Requests from a
browser are sent to a
user machines had direct access to web server, which in
databases, leading to security risks. turn executes an
application program
Database System Concepts - 7th Edition 8.6 to processKorth
©Silberschatz, theandrequest
Sudarshan
Web Interface

Web browsers have become the de-facto standard user interface to


databases
 Enable large numbers of users to access databases from anywhere
 Avoid the need for downloading/installing specialized code, while
providing a good graphical user interface
 Javascript, Flash and other scripting languages run in browser,
but are downloaded transparently
 Examples: banks, airline and rental car reservations, university
course registration and grading, an so on.

Database System Concepts - 7th Edition 8.7 ©Silberschatz, Korth and Sudarshan
Sample HTML Form

Database System Concepts - 7th Edition 8.11 ©Silberschatz, Korth and Sudarshan
Sample HTML Source Text

<html>
<body>
<table border>
<tr> <th>ID</th> <th>Name</th> <th>Department</th> </tr>
<tr> <td>00128</td> <td>Zhang</td> <td>Comp. Sci.</td> </tr>
….
</table>
<form action="PersonQuery" method=get>
Search for:
<select name="persontype">
<option value="student" selected>Student </option>
<option value="instructor"> Instructor </option>
</select> <br>
Name: <input type=text size=20 name="name">
<input type=submit value="submit">
</form>
</body> </html>

Database System Concepts - 7th Edition 8.12 ©Silberschatz, Korth and Sudarshan
Display of Sample HTML Source

Database System Concepts - 7th Edition 8.13 ©Silberschatz, Korth and Sudarshan
Three-Layer Web Architecture

The common gateway interface (CGI) standard defines how the


web server communicates with application programs.
The application program typically communicates with a database
server, through ODBC, JDBC, or other protocols, in order to get or store
data.

Database System Concepts - 7th Edition 8.15 ©Silberschatz, Korth and Sudarshan
Three-Layer Web Architecture

Using multiple levels of servers increases system overhead;


the CGI interface starts a new process to service each
request, which results in even greater overhead

Database System Concepts - 7th Edition 8.16 ©Silberschatz, Korth and Sudarshan
Two-Layer Web Architecture

Database System Concepts - 7th Edition 8.17 ©Silberschatz, Korth and Sudarshan
HTTP and Sessions

 The HTTP protocol is connectionless


 That is, once the server replies to a request, the server closes the
connection with the client, and forgets all about the request
 In contrast, Unix logins, and JDBC/ODBC connections stay connected
until the client disconnects
 retaining user authentication and other information
 Motivation: reduces load on server
 operating systems have tight limits on number of open
connections on a machine
 Information services need session information
 E.g., user authentication should be done only once per session
 Solution: use a cookie

Database System Concepts - 7th Edition 8.19 ©Silberschatz, Korth and Sudarshan
Sessions and Cookies

 A cookie is a small piece of text containing identifying information


 Sent by server to browser
 Sent on first interaction, to identify session
 Sent by browser to the server that created the cookie on further
interactions
 part of the HTTP protocol
 Server saves information about cookies it issued, and can use it when
serving a request
 E.g., authentication information, and user preferences
 Cookies can be stored permanently or for a limited time

Database System Concepts - 7th Edition 8.20 ©Silberschatz, Korth and Sudarshan
Servlets

 Java Servlet specification defines an API for communication between the


Web/application server and application program running in the server
 E.g., methods to get parameter values from Web forms, and to send
HTML text back to client
 Application program (also called a servlet) is loaded into the server
 Servlet code is executed on a web or application server
 Each HTTP request spawns a new thread in the server
 thread is closed once the request is serviced
 Programmer creates a class that inherits from HttpServlet
 And overrides methods doGet, doPost, …
 Mapping from servlet name (accessible via HTTP), to the servlet class
is done in a file web.xml
 Done automatically by most IDEs when you create a Servlet using
the IDE

Database System Concepts - 7th Edition 8.21 ©Silberschatz, Korth and Sudarshan
Example Servlet Code

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class PersonQueryServlet extends HttpServlet {
public void doGet (HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HEAD><TITLE> Query Result</TITLE></HEAD>");
out.println("<BODY>");
….. BODY OF SERVLET (next slide) …
out.println("</BODY>");
out.close();
}
}

Database System Concepts - 7th Edition 8.22 ©Silberschatz, Korth and Sudarshan
Example Servlet Code

String persontype = request.getParameter("persontype");


String number = request.getParameter("name");
if(persontype.equals("student")) {
... code to find students with the specified name ...
... using JDBC to communicate with the database ..
out.println("<table BORDER COLS=3>");
out.println(" <tr> <td>ID</td> <td>Name: </td>" + " <td>Department</td> </tr>");
for(... each result ...){
... retrieve ID, name and dept name
... into variables ID, name and deptname
out.println("<tr> <td>" + ID + "</td>" + "<td>" + name + "</td>" + "<td>" + deptname
+ "</td></tr>");
};
out.println("</table>");
}
else {
... as above, but for instructors ...
}

Database System Concepts - 7th Edition 8.23 ©Silberschatz, Korth and Sudarshan
Servlet Support

 Servlets run inside application servers such as


 Apache Tomcat, Glassfish, JBoss
 BEA Weblogic, IBM WebSphere and Oracle Application Servers
 Application servers support
 Deployment and monitoring of servlets
 Java 2 Enterprise Edition (J2EE) platform supporting objects, parallel
processing across multiple application servers, etc
 The best way to develop servlet applications is by using an IDE such as
Eclipse or NetBeans, which come with Tomcat or Glassfish servers built in

Database System Concepts - 7th Edition 8.24 ©Silberschatz, Korth and Sudarshan
Server-Side Scripting

 There are several alternatives to Java Servlets for processing requests at


the application server, including scripting languages and web application
frameworks developed for languages such as Python.

 Server-side scripting simplifies the task of connecting a database to the


Web (Java or C is a time-consuming task for Web)
 Define an HTML document with embedded executable code/SQL
queries.
 Input values from HTML forms can be used directly in the embedded
code/SQL queries.
 When the document is requested, the Web server executes the
embedded code/SQL queries to generate the actual HTML document.
 Numerous server-side scripting languages
 JSP, PHP
 General purpose scripting languages: VBScript, Perl, Python

Database System Concepts - 7th Edition 8.25 ©Silberschatz, Korth and Sudarshan
Java Server Pages (JSP)
 A JSP page with embedded Java code
 HTML programmers allowed to mix static HTML with dynamically
generated HTML.
<html>
<head> <title> Hello </title> </head> Java Code
<body>
<% if (request.getParameter(“name”) == null)
{ out.println(“Hello World”); }
else { out.println(“Hello, ” + request.getParameter(“name”)); }
%>
</body>
</html>
 JSP is compiled into Java + Servlets. JSP scripts are actually translated
into servlet code that is when compiled

Database System Concepts - 7th Edition 8.26 ©Silberschatz, Korth and Sudarshan
PHP
 PHP is a scripting language that is widely used for server-side
scripting.
 Extensive libaries including for database access using ODBC
<html>
PHP Code
<head> <title> Hello </title> </head>
<body>
<?php if (!isset($_REQUEST[‘name’]))
{ echo “Hello World”; }
else { echo “Hello, ” + $_REQUEST[‘name’]; }
?>
</body>
</html>

Database System Concepts - 7th Edition 8.27 ©Silberschatz, Korth and Sudarshan
Javascript
 Javascript very widely used
 Forms basis of new generation of Web applications (called Web 2.0
applications) offering rich user interfaces
 Javascript functions can
 Check input for validity
 Modify the displayed Web page, by altering the underling document
object model (DOM) tree representation of the displayed HTML text
 Communicate with a Web server to fetch data and modify the current
page using fetched data, without needing to reload/refresh the page
 Forms basis of AJAX technology used widely in Web 2.0
applications
 E.g. on selecting a country in a drop-down menu, the list of states
in that country is automatically populated in a linked drop-down
menu
 The browser parses HTML code into an in-memory tree structure
defined by a standard called the Document Object Model (DOM).
JavaScript code can modify the tree structure to carry out certain
operations.

Database System Concepts - 7th Edition 8.28 ©Silberschatz, Korth and Sudarshan
Javascript
 Example of Javascript used to validate form input
<html> <head>
<script type="text/javascript">
function validate() {
var credits=document.getElementById("credits").value;
if (isNaN(credits)|| credits<=0 || credits>=16) {
alert("Credits must be a number greater than 0 and less than 16");
return false
}
}
</script>
</head> <body>
<form action="createCourse" onsubmit="return validate()">
Title: <input type="text" id="title" size="20"><br />
Credits: <input type="text" id="credits" size="2"><br />
<Input type="submit" value="Submit">
</form>
</body> </html>

Database System Concepts - 7th Edition 8.29 ©Silberschatz, Korth and Sudarshan
Application Architectures

Database System Concepts - 7th Edition 8.30 ©Silberschatz, Korth and Sudarshan
Application Architectures
 To handle their complexity, large applications are often broken into several
application layers:
 The presentation or user-interface layer, which deals with user interaction.
A single application may have several different versions of this layer,
corresponding to distinct kinds of interfaces such as web browsers and
user interfaces of mobile phones, which have much smaller screens.
 In many implementations, the presentation/user-interface layer is itself
conceptually broken up into layers, based on the model-view-controller
(MVC) architecture.

Database System Concepts - 7th Edition 8.31 ©Silberschatz, Korth and Sudarshan
Application Architectures
 business-logic layer
 provides high level view of data and actions on data
– often using an object data model
 hides details of data storage schema
 data access layer
 interfaces between business logic layer and the underlying
database
 provides mapping from object model of business layer to relational
model of database

Database System Concepts - 7th Edition 8.32 ©Silberschatz, Korth and Sudarshan
Business Logic Layer
 Provides abstractions of entities
 E.g., students, instructors, courses, etc
 Enforces business rules for carrying out actions
 E.g., student can enroll in a class only if she has completed
prerequsites, and has paid her tuition fees
 Supports workflows which define how a task involving multiple
participants is to be carried out
 E.g., how to process application by a student applying to a university
 Sequence of steps to carry out task
 Error handling
 E.g. what to do if recommendation letters not received on time

Database System Concepts - 7th Edition 8.33 ©Silberschatz, Korth and Sudarshan
Application Architecture
Figure shows these layers, along with a sequence of steps
taken to process a request from the web browser.
The labels on the arrows in the figure indicate the order of
the steps.

Database System Concepts - 7th Edition 8.34 ©Silberschatz, Korth and Sudarshan
Application Architecture
When the request is received by the application
server, the controller sends a request to the model.

Database System Concepts - 7th Edition 8.35 ©Silberschatz, Korth and Sudarshan
Application Architecture
The model processes the request, using business
logic, which may involve updating objects that are
part of the model, followed by creating a result
object.

Database System Concepts - 7th Edition 8.36 ©Silberschatz, Korth and Sudarshan
Application Architecture
The model in turn uses the data-access layer to
update or retrieve information from a database.

Database System Concepts - 7th Edition 8.37 ©Silberschatz, Korth and Sudarshan
Application Architecture
.The result object created by the model is sent to the
view module, which creates an HTML view of the
result to be displayed on the web browser.

Database System Concepts - 7th Edition 8.38 ©Silberschatz, Korth and Sudarshan
Application Architecture
The view may be tailored based on the characteristics
of the device used to view the result

Database System Concepts - 7th Edition 8.39 ©Silberschatz, Korth and Sudarshan
End of Week 7

Database System Concepts - 7th Edition 8.40 ©Silberschatz, Korth and Sudarshan

You might also like