Chapter 2 - Client-Server Systems Flashcards
What is a database?
- collection of data
- links between entries
- accessible from many perspectives
6 advantages of a database
- Easy to share info
- see relationships
- avoid data duplication
- easier to enforce data security
- easier to enforce data integrity
- transaction friendly
2 types of database
Relational
Object Oriented
Describe Relational Database
Tables with mathematical relationships.
Rows=records
Columns=attributes
What is a foreign key?
A foreign key in this table is a primary key in that table
What does Java need in order to connect to a DBMS?
A driver (eg JDBC)
Statements vs prepared statements
Prepared statements are
- prepared long before execution
- compiled at the DB, not at the client
- safer from code injection
3 Layers of basic multi tier system (MVC)
- VIEW (the browsers/clients)
- CONTROL (the server)
- MODEL (DBMS/database)
What is the purpose of the CONTROLLER layer in a multi tier system?
Handles DB (SQL) transactions.
- load balancing
- concurrency control
- security
- logic & control
What protocols are used between the VIEW and CONTOLLER layer in a multitier system?
http - used between browser clients and server
What protocols are used between the CONTROLLER and MODEL layers in a multitier system?
SQL (between server and DBMS)
3 Advantages of Multitier Systems
- scale ability
- Reduce network congestion
- Flexibility (eg languages)
give 2 database models
Relational and Object-Oriented
What is a candidate key in a DB table?
a collection of attributes (column values) which can uniquely identify a single record
What is a primary key?
A candidate key made up of only one attribute… that attribute is the primary key
What is a foreign key?
when a record in one table refers to a primary key from another table, the primary key is called a foreign key
Give 6 advantages of databases
- easy sharing of info btwn processes
- can see relationships between data
- avoids data duplication
- easier to enforce security
- easier to enforce integrity
- transaction-friendly
What are the 4 steps Java goes through to communicate with a DB?
- Load Driver
- Connect
- Create Statement object & execute
- Access results in ResultSet
give the code to load a DB driver
String driver = “com.mysql.jdbc.Driver”;
Class.forName(driver);
give 2 lines of code to make the connection with a DB
String url = “jdbc:mysql//server-name:port/context-root
Connection connection = DriverManager.getConnection(url, “user”, “pwrd”);
Give a little code to go through a ResultSet:
ResultSet results = //execute statement here
while( results.next() ) {
String str = results.getString(“column-name);
Date bDay = results.getDate(1); // used row number
Create, set and execute prepared statement to get 2 values.
PreparedStatement prep = connection.prepareStatement(“SELECT attribute1 FROM table WHERE strAttr=? AND dateAttr=?”);
prep. setString(1, “name”);
prep. setString(2, myBDay);
ResultSet rs = prep.executeQuery();
Create, set and execute prepared statement to write a value.
PreparedStatement prep = connection.prepareStatement(“UPDATE table SET attribute=? WHERE primKeyAttribute=?”);
prep. setString(1, “name”);
prep. setInt(2, id);
ResultSet rs = prep.executeUpdate();
What are the three tiers of a multi-tier architecture?
Client
domain / application Server
Database server
3 advantages of multi-tier systems
- scaleability
- reduce network congestion
- flexibility
4 main actions of a server tier
- read data sent by client (usually http)
- process data
- prepare results
- send results back to client
list 6 servlet methods
- init
- service
- doGet
- doPost
- doPut
- destroy
describe the “service” method of a servlet
Called by server in a new thread on receipt of http request.
checks HTTP method type and calls doXxx, as required.
SHOULD NOT BE OVERRIDDEN
create a GET form in a url with the following attributes: firstname is John lastname is Smith server is localhost context root is servlet/FormProcessor port is 8080
http://localhost:8080/servlet/FormProcessor?firstname=John&lastname=Smith
How can session information be achieved if the client does not allow the use of cookies?
Use URL rewriting
what are the four scopes of session bean?
- page
- request
- session
- application
what are the access limitations of a session bean with a scope of “page”
can be accessed from PageContext by that JSP only during the current request
what are the access limitations of a session bean with a scope of “request”
Can be accessed from the ServletRequest object by any JSP or Servlet during the current request
what are the access limitations of a session bean with a scope of “session”
Can be accessed from the HttpSession object for the rest of the client session
what are the access limitations of a session bean with a scope of “application”
Can be accessed from ServletContext object by all JSP and Servlets
What are the three states of an EJB?
@Stateful
@Stateless
@Singleton
Give two types of EJB
session bean and
message-driven bean
purpose of EJBs
To hold the business logic of a multi-tier application, as opposed to the website and client interfacing logic
How are EJBs handled by the application server?
They are created in an EJB container, and the application server creates and deletes them as needed.
Note, there is only ever one instance of a Singleton bean
Server Tier provides CGI.
What is CDI & what are its 3 main functions?
Common Gateway Interface, handles client requests and responses:
- handle http requests and responses
- manage sessions (eg URL encoding and cookies)
- fetch & prepare results