Академический Документы
Профессиональный Документы
Культура Документы
ENTERPRISE FOUNDATIONS
ENTERPRISE ARCHITECTURAL OVERVIEW
The Components of an Enterprise System
ENTERPRISE ARCHITECTURAL OVERVIEW
Information Technology in Enterprise System
OBJECT ORIENTED SOFTWARE DEVELOPMENT FOR
THE ENTERPRISE
• Enterprise Objects
– Stage 1:Assembly Language Programming
• J2EE Model
• J2EE Features
– Specification
• The J2EE specification defines the requirements that a J2EE vendor
product implementation must satisfy
– Programming model
• The programming model is cast in the form of a developer's guide
explaining how application developers might use various aspects of
the J2EE. The guide is primarily described at a conceptual and very
high level with a sample application at the end of the guide
– Platform
• The J2EE platform is the set of integrated enterprise API library
software and development tools. The J2EE platform depends on
installation of the J2SE v1.2 platform
JAVA ENTERPRISE SYSTEM
• J2EE Features
– Reference Implementation
• The J2EE reference implementation is a sample
implementation of the underlying services utilized by
the J2EE platform APIs. It is primarily meant to be used
in early development and prototyping environments
– Compatibility Test Suite
• The compatibility test suite is used by vendors to
determine whether their implementation of the J2EE
services satisfies the J2EE specification requirements
JAVA ENTERPRISE SYSTEM
• J2EE Restriction
– EJB Application Servers
• EJB application components can queue print jobs, create socket
connections as a client (but not server connections), and read
system properties
– Web Application Servers
• Web components can also queue print jobs, create socket
connections as a client, and read system properties. Additionally,
Web components can load external libraries and can read and
write files
– Applet Clients
• Applet components can only connect to the server defined within
its CODEBASE and can read a limited set of properties
JAVA ENTERPRISE SYSTEM
• J2EE Restriction
– Application Clients
• Application client components have the most freedom
out of all J2EE-component types
• Application clients can create socket connections as a
client and accept and listen for socket connections as a
server on a local machine's ports above and including
port 1024
• Application clients can also read system properties,
queue print jobs, exit a JVM process, and load external
libraries
JAVA ENTERPRISE SYSTEM
LOGICAL ARCHITECTURE
JAVA ENTERPRISE SYSTEM
• Database Connectivity
– Data Connectivity
• Defines most of the basic JDBC functionality
– JDBC 2.0 Core API
• Includes all the functionality contained in the JDBC 1.0 version
plus a host of new features for managing query results and
manipulating new data types. The JDBC 2.0 core API is included
with the J2SE, and with the J2EE by virtue of its inclusion with the
J2SE
– JDBC 2.0 Standard Extension API
• Offers a range of more sophisticated enterprise features useful in
middle-tier servers for managing scalable database access
JAVA ENTERPRISE SYSTEM
• Communication Mechanisms
– TCP/IP
– WEB/HTTP
– CORBA/IIOP
– RMI/JRMP
– RMI/IIOP
– DCOM
– Distributed Common Services
• Naming Services, Directory Services, Trading Services, Activation Services,
Messaging Services, Transaction Services
JAVA ENTERPRISE SYSTEM
• Assurance Mechanisms
– Security
• The likelihood that your system will operate in a secure and security
breach–free fashion
– Reliability
• The likelihood that your system will operate correctly and as
intended
– Availability
• The likelihood that your system will actually be operational and
offering service. Scalability of your system to support growth in
usage is one aspect of availability
– Maintainability
• The likelihood that your system will be capable of being maintained,
upgraded, and extended for future growth
– Safety
• The likelihood that your system will operate in a safe and accident-
free manner
JAVA ENTERPRISE SYSTEM
• Client Connectivity
– Java Client
– Java Applet Client
– Web browser based client
– Non Java Client
– Dcom Based Client
• Web Connectivity
– Servlet, Jsp, HTML, XML
• Application Connectivity
– Java based Client to Non Java Based Server
– Non Java Based Client to Java Based Server
JAVA ENTERPRISE SYSTEM
• JDBC Architecture
• JDBC Drivers and Their Types
• JDBC Driver Configuration
• JDBC Connections
• JDBC Statements
• JDBC Result set
• Sql and Java Mapping
• JDBC MetaData
BASIS OF JDBC
• JDBC Architecture
BASIS OF JDBC
• JDBC
– Java Database Connectivity (JDBC) is a standard Java API to interact with relational
databases form Java.
– JDBC has set of classes and interfaces which can use from Java application and talk to
database without learning RDBMS details and using Database Specific JDBC Drivers.
• JDBC Architecture
– The JDBC API, which provides the application-to-JDBC Manager connection
– The JDBC Driver API, which supports the JDBC Manager-to-Driver Connection
– The JDBC API uses a driver manager and database-specific drivers to provide transparent
connectivity to heterogeneous databases
– The JDBC driver manager ensures that the correct driver is used to access each data
source
– The driver manager is capable of supporting multiple concurrent drivers connected to
multiple heterogeneous database
– The location of the driver manager with respect to the JDBC drivers and the Java
application is shown in Figure 1
BASIS OF JDBC
• Main components of JDBC
– DriverManager
• Manages a list of database drivers
• Matches connection requests from the java application with the proper database driver
using communication subprotocol
• The first driver that recognizes a certain subprotocol under JDBC will be used to
establish a database Connection
– Driver
• The database communications link, handling all communication with the database.
Normally, once the driver is loaded, the developer need not call it explicitly
– Connection
• Interface with all methods for contacting a database. The connection object represents
communication context, i.e., all communication with database is through connection
object only
– Statement
• Encapsulates an SQL statement which is passed to the database to be parsed,
compiled, planned and executed.
– ResultSet
• The ResultSet represents set of rows retrieved due to query execution
BASIS OF JDBC
• How the JDBC application works
– A JDBC application can be logically divided into two layers:
• Driver layer
• Application layer
• Driver layer consists of DriverManager class and the
available JDBC drivers
• The application begins with requesting the DriverManager
for the connection
• An appropriate driver is choosen and is used for establishing
the connection. This connection is given to the application
which falls under the application layer
• The application uses this connection to create Statement
kind of objects, through which SQL commands are sent to
backend and obtain the results
BASIS OF JDBC
• Advantage
• The JDBC-ODBC Bridge allows access to almost any database, since the database's
ODBC drivers are already available
• Disadvantages
– Since the Bridge driver is not written fully in Java, Type 1 drivers are not portable
– A performance issue is seen as a JDBC call goes through the bridge to the ODBC driver,
then to the database, and this applies even in the reverse process. They are the
slowest of all driver types
– The client system requires the ODBC Installation to use the driver
– Not good for the Web
BASIS OF JDBC
– Type 1
BASIS OF JDBC
• Type 2 JDBC Driver
– Native-API/partly Java driver
– The distinctive characteristic of type 2 jdbc drivers are that Type 2 drivers convert JDBC calls
into database-specific calls
– i.e. this driver is specific to a particular database
– Some distinctive characteristic of type 2 jdbc drivers are shown below
– Example: Oracle will have oracle native api
• Advantage
– The distinctive characteristic of type 2 jdbc drivers are that they are typically offer better
performance than the JDBC-ODBC Bridge as the layers of communication (tiers) are less than
that of Type 1 and also it uses Native api which is Database specific
• Disadvantage
– Native API must be installed in the Client System and hence type 2 drivers cannot be used
for the Internet
– Like Type 1 drivers, it’s not written in Java Language which forms a portability issue
– If we change the Database we have to change the native api as it is specific to a database
– Mostly obsolete now
– Usually not thread safe
BASIS OF JDBC
• Type 2 JDBC Driver(Native-API/partly Java driver)
BASIS OF JDBC
• Type 3 JDBC Driver
– All Java/Net-protocol driver
– Type 3 database requests are passed through the network to the middle-tier server
– The middle-tier then translates the request to the database. If the middle-tier server can in
turn use Type1, Type 2 or Type 4 drivers
• Advantage
– This driver is server-based, so there is no need for any vendor database library to be present
on client machines
– This driver is fully written in Java and hence Portable. It is suitable for the web
– There are many opportunities to optimize portability, performance, and scalability
– The net protocol can be designed to make the client JDBC driver very small and fast to load
– The type 3 driver typically provides support for features such as caching (connections, query
results, and so on), load balancing, and advanced system administration such as logging and
auditing
– This driver is very flexible allows access to multiple databases using one driver
– They are the most efficient amongst all driver types
• Disadvantage
– It requires another server application to install and maintain
– Traversing the recordset may take longer, since the data comes through the backend server
BASIS OF JDBC
• Type 3 JDBC Driver
• All Java/Net-protocol driver
BASIS OF JDBC
• Type 4 JDBC Driver
• Native-protocol/all-Java driver
– The Type 4 uses java networking libraries to communicate directly with the
database server
• Advantage
– The major benefit of using a type 4 jdbc drivers are that they are completely
written in Java to achieve platform independence and eliminate deployment
administration issues. It is most suitable for the web
– Number of translation layers is very less i.e. type 4 JDBC drivers don't have to
translate database requests to ODBC or a native connectivity interface or to
pass the request on to another server, performance is typically quite good
– You don’t need to install special software on the client or server. Further,
these drivers can be downloaded dynamically
• Disadvantage
– With type 4 drivers, the user needs a different driver for each database.
BASIS OF JDBC
• Type 4 JDBC Driver
• Native-protocol/all-Java driver
BASIS OF JDBC
• Basic Steps in writing a Java program using JDBC
– Load the RDBMS specific JDBC driver because this driver actually
communicates with the database
– Open the connection to database which is then used to send SQL statements
and get results back
– Create JDBC Statement object. This object contains SQL query
– Execute statement which returns resultset(s). ResultSet contains the tuples
of database table as a result of SQL query
– Process the result set
– Close the connection
BASIS OF JDBC
• What is Statement
– Statement acts like a vehicle through which SQL commands can be sent
– Through the connection object we create statement kind of objects
– Statement stmt = conn.createStatement();
– This method returns object which implements statement interface
• PreparedStatement
– A prepared statement is an SQL statement that is precompiled by the database
– Through precompilation, prepared statements improve the performance of SQL
commands that are executed multiple times (given that the database supports
prepared statements)
– Once compiled, prepared statements can be customized prior to each execution by
altering predefined SQL parameters
• ResultSetMetaData
– Interface holds information on the types and properties of the columns in a ResultSet.
It is constructed from the Connection object
BASIS OF JDBC
• DATABASE URLs
– A database Uniform Resource Locator (URL) represents a fully
qualified database connection name identifying the database and
database driver to which you are connecting
– jdbc:subprotocol:subname
– jdbc is a database driver type keyword used in the URL for all JDBC
database URLs
– subprotocol represents the type of database to which one desires
connectivity
– subname provides additional information needed by the database
type for establishing connectivity.
• The subprotocol and subname to use for a particular database instance
should be described in your JDBC driver vendor's documentation
• but some examples are listed here for different driver types
BASIS OF JDBC
• DATABASE URLs
– Type 1: JDBC-ODBC Bridge Driver URLs
• jdbc:odbc:customer;UID:dba;pwd:dba
• jdbc:odbc:customer;CacheSize=100
• jdbc:odbc:<datasource name>;param=value;param=value;….
• Batch Updates
– JDBC batch update is a collectively called when a group of SQL statements
are executed simultaneously to a database as a single unit
– The batch is sent to the database in a single request using connection object
– The advantage of batch is to reduce the network calls between the front end
application and its database rather than executing single SQL statement
• Batch Updates
– executeQuery ( ) : This method is used to retrieve the records from the
database using select query
– rs.next ( ) : This method return you the next successive value in the element
series
•
• st = con.createStatement();
st.addBatch("update person set cname='Ajay' where id='1'");
st.addBatch("update person set cname='Komal' where id='2'");
st.addBatch("update person set cname='Santosh' where id='3'");
st.executeBatch();
ADVANCED JDBC FEATURES
• Row Sets
– JDBC RowSet is an interface of javax.sql.rowset interface
– This interface is wrapper around a ResultSet object that makes
possible to use resultSet as java beans object
– It can be one bean that makes available for composing of an
application
– Because a it continually maintain a connection JDBC connection to
the database
– Another advantage of JDBC RowSet is that it is used to makes
ResultSet object scrollable and updateable
– By default all the RowSet object are scrollable and updateable
ADVANCED JDBC FEATURES
• Row Sets
– import javax.sql.rowset.JdbcRowSet;
– JdbcRowSet jdbcRowSet =
new JdbcRowSetImpl(connection);
jdbcRowSet.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
String queryString = "SELECT * FROM student";
jdbcRowSet.setCommand(queryString);
jdbcRowSet.execute();
while (jdbcRowSet.next()) {
// Generating cursor Moved event
System.out.println("Roll No- " + jdbcRowSet.getString(1));
System.out.println("name- " + jdbcRowSet.getString(2));
}
ADVANCED JDBC FEATURES
• Stored Procedures
– A stored procedure is a subroutine available to applications that
access a relational database system. A stored procedure (sometimes
called a proc, sproc, StoPro, StoredProc, or SP) is actually stored in
the database data dictionary
– Stored procedures are precompiled database queries that improve
the security, efficiency and usability of database client/server
applications
– Developers specify a stored procedure in terms of input and output
variables
– They then compile the code on the database platform and make it
available to aplication developers for use in other environments,
such as web applications
– All of the major database platforms, including Oracle, SQL Server and
MySQL support stored procedures
ADVANCED JDBC FEATURES
• Stored Procedures
– CREATE PROCEDURE sp_GetInventory
@location varchar(10)
AS
SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = @location
• Database Naming
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
final class JDBCCONDATASRC {
String DATASOURCE_CONTEXT = "java:comp/env/jdbc/blah";
Connection result = null;
try {
Context initialContext = new InitialContext();
DataSource datasource = (DataSource)
initialContext.lookup(DATASOURCE_CONTEXT);
result = datasource.getConnection();
} catch (NamingException ex) {
log("Cannot get connection: " + ex);
} catch (SQLException ex) {
log("Cannot get connection: " + ex);
}
}
ADVANCED JDBC FEATURES
• Connection Pools
– Connection pooling is a technique of creating and managing a pool of
connections that are ready for use by any thread that needs them.
• Distributed Transaction
– A distributed transaction is a transaction that updates data on two or
more networked computer systems
– Distributed transactions extend the benefits of transactions to
applications that must update distributed data
– Implementing robust distributed applications is difficult because
these applications are subject to multiple failures, including failure of
the client, the server, and the network connection between the client
and server
– In the absence of distributed transactions, the application program
itself must detect and recover from these failures.
ADVANCED JDBC FEATURES
• Distributed Transaction
– two-phase commit algorithm
– local transaction manager
– Resource managers manage persistent or durable data
– global commit coordinator
END OF UNIT-1