Title: Assignment
1Assignment
- One assignment (30 of course)
- nothing for parallel programming
- Build a 3-tier system using Java, CORBA and JDBC
- Instructions on www.ecs.soton.ac.uk/notes/cm319
- Due Tuesday 21st March 1600.
2CORBA and Databases
- Servers tend not to work in isolation
- rely on a persistent data store
- Persistent store could be
- standard files
- database
- Object Oriented
- Relational
- Object-Relational
3And finally, the model is...
- This is a 3-tier model
- 1st tier - client
- 2nd/middle tier - server
- 3rd tier - database
CORBA
JDBC
42-tier vs 3-tier (I)
- 3-tier benefits
- Less network traffic
- Client can get processed results from server,
rather than large amounts of raw data - Flexible distribution of client/server logic
- Computationally intensive work can be placed on
high performance servers (Thin/Fat Clients) - Security Advantages
- protocol between the tiers one and two is user
defined, and can use encryption - designer can specify legal operations on data,
rather than allowing uncontrolled access to the
raw data
52-tier vs 3-tier (II)
- Load balancing and scheduling
- server objects can be duplicated and distributed
across multiple server platforms - Middle tier logic can incorporate load balancing
and scheduling - Application Reuse
- Distributed object technology allows the
development of reusable components with well
defined interfaces
6Writing a Java/JDBC program
- Program accessing the database must perform the
following tasks - Load the appropriate JDBC driver
- Connect to the database
- Issue SQL queries/updates to the database
- Process results returned by the database
- disconnect from the database
- We first consider a 2-tier model
7Step1 - Load the appropriate JDBC driver
- Each JDBC compliant database will have a driver
- Java Class
- IBM DB2 driver - COM.ibm.db2.jdbc.net.DB2Driver
- mSQL driver - COM.imaginary.sql.msql.MsqlDriver
- Driver must be loaded by the client
- recommended method is using Class.forName
method which explicitly loads and links specified
driver - e.g.,
- Class.forName (COM.ibm.db2.jdbc.net.DB2Driver)
- gt class must be installed on client
8Step 2 - Connect to the Database
- Identify the machine and database to connect to
- Database connections are based on URL naming
- jdbcltsubprotocolgtltsubnamegt
- jdbc - indicates protocol being used
- subprotocol - driver name or connectivity
mechanism (db2/msql/odbc) - subname - machine name and port number of
database machine, and the database name - //hostnameport/databaseName
- e.g., a complete JDBC URL
- String urljdbcdb2//wombat.ecs.soton.ac.uk1114
/sample - Connection to database made by
- String userid yourUserID
- String passwd yourPassword
- Connection myDbCon Drivermanager.getConnection
(url, userid, passwd)
9Step 3 - Issuing Queries to Database (I)
- To issue a query need a Statement object (simple
statement) - Statement myStmt myDbCon.createStatement()
- Alternative statements are prepared and
callable - Statement provides 3 methods for executing SQL
statements depending on the returned value - ResultSet myResults myStmt.executeQuery(String)
- returns a table of results (select statements)
- int numResults myStmt.executeUpdate(String)
- returns number of rows affected (insert,
update, delete) - boolean resultSetExists myStmt.execute(String)
- not commonly used - if query could return
multiple resultSets
10Step 3 - Issuing Queries to Database (II)
- E.g.,
- ResultSet myRs myStmt.executeQuery (Select
title, author from BOOKS where price lt 10) - int numChanges myStmt.executeUpdate (UPDATE
BOOKS SET price 10.99 WHERE ISBN
ISBN0-13-766957-7) - Note that can only have one ResultSet object
per Statement - gt cannot interleave reading multiple resultSets
with a single statement - By default, all executeUpdate methods commit
after executing each statement (auto-commit) - auto-commit can be switched off in Connection
class, but it is then the users responsibility to
commit changes
11Step 4 - Processing the results
- ResultSet contains rows and columns of data
- Access provided by
- getXXX () methods to access column data in
current row - mapping between datatypes in SQL and Java
- Access data given a column name or number
(starting at 1) - Column names are not case sensitive
- String s rs.getString (title)
- String s rs.getString (2)
- next() method - moves cursor to next row of
results - returns false when no more results
12(No Transcript)
13Step 5 - Closing resources
- Should close statements and connection after use
- Database permits only a limited number of open
statements and connections - myrs.close()
- myStmt.close()
- myDbCon.close()
14Assignment
- Using Java, build a 3-tier system consisting of a
graphical client that uses CORBA to invoke
methods on a middle layer which in turn uses JDBC
to connect to a database. The core system will be
minimal, based on given IDL and with a specified
database structure. You must implement this
minimal system and also extend it in some way.
15Assignment Minimal System
- The minimal system contains a database with a
single table consisting of two columns of
floating point numbers. The IDL is provided and
contains CORBA operations that control connection
and disconnection from the database along with an
operation that mimics "business logic" by
performing a certain check on the data. The
graphical client provides buttons that control
these operations and a way of displaying the
numerical result of the check.
16Assignment Minimal System IDL
- module CM319
-
- interface minimal
-
- boolean Connect(in string url)
- void Disconnect()
- double Check()
-
17Assignment Extended System
- You must also extend this minimal system in some
way. This extension must involve some change to
the IDL and for example - A more functional middle layer
- Use of alternative ORB's, programming languages
or JDBC drivers - Use of a nameserver
- An Applet client
- A factory pattern.
18Building 3-tier applications (I)
- No fixed rule for how the middle-tier accesses
the database. 3 Options - single database connection
- middle-tier accesses the database through a
single connection - if clients require access to database, it is via
a shared, synchronized object model - applicable when only the server requires direct
access to the database. Clients may access a
shared object that contains processed database
information - e.g., Server uses database to store marks, and
creates a local object to compute standard
deviation, average, etc functions. As clients
request the same information, clients issue
requests to the shared object.
19Building 3-tier applications (II)
- multiple database connections, created by server
on startup (Connection Pool) - server creates a pool of connections on startup
- synchronized object holds all connections
- clients are allocated a connection when needed
and return connection to the pool when no longer
needed - clients could be queued or refused a connection
if no free database connections exist (or pool
could be expanded) - issues
- clients all have same access privileges, but
- no overhead in creating a database connection -
best performance - supports random database queries by clients
20Building 3-tier applications (III)
- multiple database connections, created on demand
for clients - middle-tier uses factory model to create a
database connection object for each client - used when each client needs to access the
database directly with client specific privileges - issues
- most flexible, but most expensive - high overhead
in creating connections initially - server could also define and ensure that the
number of connections do not exceed a specified
number (Similar to Pooling connections)