Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations

Presentation on theme: "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."— Presentation transcript:

1 Clients and Server

2 Clients and servers A 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.

3 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

4 Some servers File servers Database servers Groupware servers Web servers Mail servers Object servers Print servers

5 Web servers In ecommerce terms the most important type of server Deal with in detail later Stores HTML files and dispenses them to clients Processes forms details Communicates with other servers, for example database servers

6 Database servers Next to web servers the most important type of server for ecommerce Explained in more detail later Stores relational databases Responds to queries in language called SQL

7 Tiered archtiectures An example of separation of concerns. Most popular model has three layers Developed for maintenance reasons

8 Three-tier model Business objects Business objects Database Clients Presentation layer Processing layer Data layer

9 Three tiers Presentation layer contains HCI for client Processing layer contains business objects Data layer contains some stored data

10 Rationale HCI can go on the client and does not require to be transmitted over network Business objects reflect domain entities Business objects shield the implementation of data

11 Business objects Reflect entities in application, for example in a sales site: catalogue, product and customer All application programming done on business objects Details of underlying data hidden to the application programmer, for example the programmer should be unaware of the database technology

12 Database Servers

13 Database servers Have been in existence for some time. Described here as they play a major part in ecommerce systems Virtually all based on the relational model

14 Relational tables ItemId Item NoInStock Aw222 Washer A 300 Ntr444 Nut A2009 Edt666 Spanner S802 Bt555qw Bolt B200 Key Each row contains associated data

15 SQL Structured Query Language In existence for many years Used to create, modify and retrieve data from relational tables No standardised

16 An example Select EmployeeName, Salary From Employees WHERE Salary>3500 Names of columns Name of table Condition

17 Typical configuration Web server Database server Clients

18 Functions of a database server Interpret SQL statements and execute them Optimise queries To prevent concurrency errors To detect deadlock To administer security To administer backup

19 Stored procedures Snippets of compiled code which are equivalent to subroutines Stored at server Efficient alternative to sending large numbers of SQL statements over communication media

20 Stored procedures: for and against Plus More efficient in processing time Reduces network traffic Keeps database code close to the database Minus They are non- standard Optimisation needs to be repeated as access strategies to a database change

21 Referential integrity Tables in a relational database are consistent with each other Associated with business rules Two ways of implementing it: declarative referential integrity and trigger-based referential integrity

22 Implementation Declarative referential integrity is maintained by declarations in database schemas Trigger based referential integrity is achieved by embedding code

23 Pros and cons Trigger based Non-standard Triggers found scattered throughout a system Some implementations have upper limit to number of triggers Declaration based Self-documenting Standard

24 Relational middleware Server software Server software Clients Database SQL API Driver Stacks

25 The components The API provides programmer facilities The driver communicates SQL statements to the server software The stack contains protocol software Server software carries out the main functions, for example executing SQL queries

26 Distributed databases Databases spread around servers in a distributed system Databases distributed for performance reasons: keeping data close to clients Distributed for reliability using replicated data Distributed because of legacy: many systems have evolved from separate systems

27 Problems with distributed data Keeping replicated data up-to-date Ensuring concurrent access keeps a database in its correct state Security is a big headache Reliability is a problem Clock synchronisation is a problem

28 Types of distribution Downloading: periodically writing data to a remote database Data replication: keeping identical sets of data in step Fragmentation: splitting data into sub- tables.

29 Fragmentation Horizontal fragmentation, splitting tables lengthways - split tables have the same columns as original table Vertical fragmentation, where the split tables are associated with a subset of the columns of the original table

30 Java as a medium for database development (i) Driver, used for database drivers Statement, an SQL statement PreparedStatement, compiled SQL statements CallableStatement, stored procedure

31 Java as a medium for database development (ii) Connection, facilities for connecting to a database ResultSet, collection of data retrieved from a query DatabaseMetaData, data about a database DriverManager, manages connections to a database

32 Developing Java code to access a database Load a driver Establish a database connection Associate an SQL statement with this connection Execute the statement Process a result set Close the connection

33 Loading the driver //Set the name of the file that is to be accessed //and the name of the driver String 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); }

34 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,);

35 Create and execute an SQL statement // Create a statement object Statement selectStatement = con.createStatement(); // Execute the SQL select statement ResultSet rs = selectStatement.executeQuery (SELECT name, salary FROM employees WHERE salary >35000");

36 Process the result set String employeeName; int employeeSalary; while( { employeeName = rs.getString(1); employeeSalary = rs.getInt(2); System.out.println(Name = + employeeName + Salary = + employeeSalary); }

37 Close down connections //Close down the database connection, result set //and the SELECT statement selectStatement.close(); con.close(); rs.close();

38 Meta data Data about data Can be data about a database, a result set or a driver Java contains classes which enable such data to be easily extracted

39 An example Connection c; // Code to establish a connection DatabaseMetaData dmd = c.getMetaData(); System.out.println(Driver is + dmd.getDriverName() + Version number = +dmd.getDriverVersion()); Obtaining data about the driver: its name and version number

40 Three tier with relational database Clients Business objects Relational databases Mapping

41 Mappings Classes usually mapped to tables Instance variables to columns Relationships to common data in tables

Download ppt "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."

Similar presentations

Ads by Google