Top Banner
Clients and Server
41

Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Mar 28, 2015

Download

Documents

Adam McGinnis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Clients and Server

Page 2: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Clients and serversA server provides a service such as dispensing files.A client calls on a service.The distinction is not hard and fast a server may act as a client to another server.

Page 3: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

A server acting as a client

In an ecommerce application a Web server might call on the service of a database server in order to access some data such as catalogue records

Page 4: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Some serversFile serversDatabase serversGroupware serversWeb serversMail serversObject serversPrint servers

Page 5: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Web serversIn ecommerce terms the most important type of serverDeal with in detail laterStores HTML files and dispenses them to clientsProcesses forms detailsCommunicates with other servers, for example database servers

Page 6: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Database serversNext to web servers the most important type of server for ecommerceExplained in more detail laterStores relational databasesResponds to queries in language called SQL

Page 7: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Tiered archtiecturesAn example of separation of concerns.Most popular model has three layersDeveloped for maintenance reasons

Page 8: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Three-tier model

Business objects

Business objects DatabaseDatabase

Clients

Presentation layer Processing layer Data layer

Page 9: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Three tiersPresentation layer contains HCI for clientProcessing layer contains business objectsData layer contains some stored data

Page 10: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

RationaleHCI can go on the client and does not require to be transmitted over networkBusiness objects reflect domain entitiesBusiness objects shield the implementation of data

Page 11: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Business objectsReflect entities in application, for example in a sales site: catalogue, product and customerAll application programming done on business objectsDetails of underlying data hidden to the application programmer, for example the programmer should be unaware of the database technology

Page 12: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Database Servers

Page 13: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Database serversHave been in existence for some time.Described here as they play a major part in ecommerce systemsVirtually all based on the relational model

Page 14: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Relational tables

ItemId Item NoInStock

Aw222 Washer A 300

Ntr444 Nut A 2009

Edt666 Spanner S 802

Bt555qw Bolt B 200

KeyEach row contains associated data

Page 15: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

SQLStructured Query LanguageIn existence for many yearsUsed to create, modify and retrieve data from relational tablesNo standardised

Page 16: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

An example

Select EmployeeName, Salary From Employees WHERE Salary>3500

Names of columns

Name of table

Condition

Page 17: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Typical configuration

Web server Databaseserver

Clients

Page 18: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Functions of a database server

Interpret SQL statements and execute themOptimise queriesTo prevent concurrency errorsTo detect deadlockTo administer securityTo administer backup

Page 19: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Stored proceduresSnippets of ‘compiled’ code which are equivalent to subroutinesStored at serverEfficient alternative to sending large numbers of SQL statements over communication media

Page 20: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Stored procedures: for and against

PlusMore efficient in processing timeReduces network trafficKeeps database code close to the database

MinusThey are non-standardOptimisation needs to be repeated as access strategies to a database change

Page 21: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Referential integrityTables in a relational database are consistent with each otherAssociated with business rulesTwo ways of implementing it: declarative referential integrity and trigger-based referential integrity

Page 22: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

ImplementationDeclarative referential integrity is maintained by declarations in database schemasTrigger based referential integrity is achieved by embedding code

Page 23: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Pros and consTrigger based

Non-standardTriggers found scattered throughout a systemSome implementations have upper limit to number of triggers

Declaration basedSelf-documentingStandard

Page 24: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Relational middleware

Serversoftware

Serversoftware

Clients

DatabaseDatabase

SQL API

Driver

Stacks

Page 25: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

The componentsThe API provides programmer facilitiesThe driver communicates SQL statements to the server softwareThe stack contains protocol softwareServer software carries out the main functions, for example executing SQL queries

Page 26: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Distributed databases

Databases spread around servers in a distributed systemDatabases distributed for performance reasons: keeping data close to clientsDistributed for reliability using replicated dataDistributed because of legacy: many systems have evolved from separate systems

Page 27: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Problems with distributed data

Keeping replicated data up-to-dateEnsuring concurrent access keeps a database in its correct stateSecurity is a big headacheReliability is a problemClock synchronisation is a problem

Page 28: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Types of distributionDownloading: periodically writing data to a remote databaseData replication: keeping identical sets of data in stepFragmentation: splitting data into sub-tables.

Page 29: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

FragmentationHorizontal fragmentation, splitting tables lengthways - split tables have the same columns as original tableVertical fragmentation, where the split tables are associated with a subset of the columns of the original table

Page 30: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Java as a medium for database development (i)Driver, used for database driversStatement, an SQL statementPreparedStatement, ‘compiled SQL statements’CallableStatement, stored procedure

Page 31: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Java as a medium for database development (ii)Connection, facilities for connecting to a databaseResultSet, collection of data retrieved from a queryDatabaseMetaData, data about a databaseDriverManager, manages connections to a database

Page 32: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Developing Java code to access a database

Load a driverEstablish a database connectionAssociate an SQL statement with this connectionExecute the statementProcess a result setClose the connection

Page 33: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Loading the driver //Set the name of the file that is to be accessed

//and the name of the driverString fileURL = “...”;String driverName = “...”;try{ // Load in the driver programmatically

Class.forName(driverName);}catch (ClassNotFoundException cfn){

//Problem with driver, display error message and //return to operating system with status value 1 System.out.println(“Problem loading driver”); System.exit(1);}

Page 34: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Establishing a connection

try{ //Establish a connection to the database, second //argument is the name of the user and the third //argument is a password (blank) Connection con = DriverManager.getConnection(fileURL, “Darrel”,””);

Page 35: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Create and execute an SQL statement

// Create a statement objectStatement selectStatement = con.createStatement();// Execute the SQL select statementResultSet rs = selectStatement.executeQuery (“SELECT name, salary FROM employees WHERE salary >35000");

Page 36: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Process the result set

String employeeName;int employeeSalary;while(rs.next()){ employeeName = rs.getString(1); employeeSalary = rs.getInt(2); System.out.println(“Name = “+ employeeName + “Salary = “+ employeeSalary);}

Page 37: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Close down connections

//Close down the database connection, result set//and the SELECT statementselectStatement.close();con.close();rs.close();

Page 38: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Meta dataData about dataCan be data about a database, a result set or a driverJava contains classes which enable such data to be easily extracted

Page 39: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

An example

Connection c;// Code to establish a connectionDatabaseMetaData dmd = c.getMetaData();System.out.println(“Driver is ”+ dmd.getDriverName() +

“ Version number = “+dmd.getDriverVersion());

Obtaining data about the driver: its name and version number

Page 40: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Three tier with relational database

Clients

Businessobjects

Relationaldatabases

Mapping

Page 41: Clients and Server. Clients and servers A server provides a service such as dispensing files. A client calls on a service. The distinction is not hard.

Mappings

Classes usually mapped to tablesInstance variables to columnsRelationships to common data in tables