Extreme Java G22.3033-007
Session 12 - Main Theme Java Database Technologies (Part I)
Dr. Jean-Claude Franchitti
New York University Computer Science Department Courant Institute of Mathematical Sciences
1
Agenda
Summary of Previous Session
Applications of Java to Database Technology
Database Technology Review
Basic and Advanced JDBC Features
J2EE Enterprise Data Enabling
XML and Database Technology
Readings
Class Project & Assignment #5a
2
1 Summary of Previous Session
Summary of Previous Session
Enterprise JavaBeans (EJBs)
J2EE Connector Architecture
Practical Survey of Mainstream J2EE App. Servers
Web Services Developer Pack
Enterprise Application Integration (EAI) and Business to Business Integration (B2Bi)
J2EE Blueprint Programs
Class Project & Assignment #4c
3
Part I
Java and Database Technology
Also See Session 12 Handout on: “Java and Database Technology (JDBC)”
and Session 12 Presentation on: “Designing Databases for eBusiness Solutions”
4
2 Review of Database Technology
Introduction to Database Technology
Data Modeling
Conceptual Database Design
Logical Database Design
Physical Database Design
Database System Programming Models
Database Architectures
Database Storage Management
Database System Administration
Commercial Systems: www.oracle.com,www.ibm.com/db2, http://www- 3.ibm.com/software/data/informix/,www.sybase.com 5
Advanced Database Concepts
Parallel and Distributed Databases
Web Databases
Data Warehousing and Data Mining
Mobile Databases
Spatial and Multimedia Databases
Geographic Information Systems
Active Databases
Temporal Databases
Deductive Databases 6
3 Java and Database Technology
JavaSpaces
Create and store objects with persistence
Allow process integrity
http://www.javasoft.com/products/javaspaces/index.html
JDBC Data Access API
Access tabular data sources from Java
http://www.javasoft.com/products/jdbc/index.html
J2EE database access and container managed persistence (http://java.sun.com/j2ee/j2sdkee/techdocs/guides/ejb/html/DevGuideTOC.html)
Pjama: Orthogonal Persistence for the Java Platform
http://www.sun.com/research/forest/opj.main.html
http://www.dcs.gla.ac.uk/pjava/
7
JDBC: Pure Java and ODBC-Drivers
8
4 Basic and Advanced JDBC
See Session 12 Handouts:
Java and Database Technology - JDBC
Enterprise JavaBeans Patterns
See Session 12 Demo Programs on JDBC
Java databases
http://sourceforge.net/projects/hsql/
http://www.pointbase.com/
9
JDBC API 3.0 (http://java.sun.com/products/jdbc/index.html, http://www.wiley.com/extras/jdbc_3_java_db_connectivity/)
JDBC Technology Core features (java.sql package)
Scrollable result sets
Updatable result sets
Batch updates
Savepoints
JDBC Optional Package features (javax.sql package)
JNDI support
Connection pooling
Distributed transactions
Rowset objects (JavaBeans)
Statement pooling 10
5 URL-Based Database Connection
11
Java and ODBs
Related Developments:
Persistent Object Stores
Object-Oriented Database Management Systems
Object/Relational Mapping Automation
See Object-Oriented Database Articles at
http://www.odbmsfacts.com/
Java Data Objects (JDO) API (http://access1.sun.com/jdo)
Transparent database access
Suitable implementation for
Persistent helper classes for session beans
Delegate classes for BMP Entity Beans
Delegate classes for CMP Entity Beans 12
6 Part II
Introduction to J2EE Enterprise Data Enabling
Also See Session 12 Handouts on: “Enterprise JavaBeans Patterns” “Persistence in EJB Frameworks” “Efficient CMP Development”
13
Entity Beans in EJB Application Servers
Represent sets of data (all or part of a database table or a view)
Functionality limited to creation, update, and deletion of data
Manage persistence of data
Maintained in a cache
Can be container or bean managed
Container-managed beans are under the control of an application server for persistence and transaction management
Container-managed beans are restricted in the type and complexity of data they can manage
Bean-managed beans rely on user provided code for persistence and transaction management
14
7 Session Beans in EJB Application Servers
Handle the business logic of EJB applications
May use multiple entity beans to gather application data
15
EJB Component/Programming Model
16
8 Anatomy of a CMP Bean
EJB remote interface (extends javax.ejb.EJBObject)
Contains method signatures for any method that accesses or modifies data stored in the bean
EJB remote implementation (implements javax.ejb.EntityBean)
Provides an implementation of all the methods defined in the remote interface, in addition to methods required by the application server
EJB home interface (extends javax.ejb.EJBHome interface)
Declares method signatures for any method that creates new instances of the bean, and for all methods that are used to retrieve instances of the bean (finder methods
EJB key
Contains the unique primary key implementation for the bean
any class that is a legal value type in RMI-IIOP 17
Anatomy of a CMP Bean (continued)
EJB finder helper interface (optional)
Contains one static java.lang.String field for each finder method declared in the EJB home interface
Strings are initialized with SQL queries executed dynamically when bean instances are retrieved in a finder method
Some server ignore this file and put queries in XML deployment descriptors using proprietary query language formats
Deployment descriptor (XML -> serialized data object)
Names of EJB classes/interfaces, list of persistent fields, etc.
Database scripts
Application server may generate them
18
9 EJB Implementation Process (WSAD)
Create EJB Project
Create (Stateful) Session Beans
Create CMP Entity Beans
Create CMRs as needed (EJB 2.0 Assumed)
Create custom finder methods using EJB QL as needed
Map CMP Entity Beans to a Relational Database
Specify J2EE References to EJBs and Resources Required by EJBs
Integrate EJBs with Web Module “Model” Objects as Needed
19
EJB Generation (e.g., IBM EJBMaker, BEA WebGain Studio)
10 EJB 2.0 Query Language: EJB QL
SQL-like language for expressing selection criteria over the domain of 2.0 CMP EJBs
Database-agnostic query language that can be mapped to virtually any relational backend
Used to implement EJB custom finders
Look under the “Bean” tab of the EJB deployment descriptor in WSAD and scroll down to “Queries | Add”
e.g., SELECT OBJECT(i) FROM Inventory i WHERE i.category=?1
Also used to implement ejbSelect() methods, which are EJB queries accessible to the bean implementation only
21
SQLJ (www.sqlj.org)
Defines the “style” of database access
JDBC implies “dynamic” access
SQLJ is a standard for static SQL usage
Provides performance enhancements over dynamic SQL
Provides “SELECT INTO” statement to populate Java variables directly from the result of an SQLJ statement (no need for cursors)
Three stages required
SQLJ code generation
Translation of SQLJ code to Java
Profiling of Java code against specific database used 22
11 IBM WAS Persistence Extensions
Access Intent
Default is “Pessimistic Update with weakest lock at load”)
Application Profile (provides “dynamic” access intent)
EJB Persistence Support Extensions (e.g., EJB inheritance)
EJB QL Extensions (e.g., ORDER BY)
Transactions (unit-of-work scoping)
Support for JCA and JDNC-based local transactions to define what goes on when the transaction context is “unspecified” as per the EJB 2.0 specification
ActivitySession Service
Goal is to retain contained EJBs beyond a given transaction 23
Container Managed Persistence Architecture (review)
24
12 Bean Managed Persistence Architecture (review)
25
JDBC in the J2EE Architecture
26
13 EJB Persistence Service Architecture
See Persistence Service Interface for Entity Beans:
http://jsp.java.sun.com/javaone/javaone2000/pdfs/TS-1498.pdf
See Jboss Persistence Manager Architecture:
JAWS (Just Another Web Store) is the default CMP (Container Manager Persistence) plugin that performs basic O/R functionality against a JDBC-store
See Patterns for Object Relational Access Layers
http://www.objectarchitects.de/ObjectArchitects/orpatterns/EJBPersistence
See Session 13 Handout on “Persistence in EJB Frameworks”
27
EJB Development Approach #1
Handcode Everything:
EJB remote interface
EJB remote implementation
EJB home interface
EJB key
EJB finder helper interface
Deployment descriptor
Database scripts
28
14 EJB Development Approach #2: Handcode the Bean and Descriptor
29
EJB Development Approach #3: Graphical Bean and Descriptor Generator
30
15 Persistence Service Performance Issues
Complexity of an optimal access layer
Object to Tuple Layer Logical Mapping
Physical Layer Mapping
Caching to reduce database traffic and disk I/O
Data Clustering
Application must still be maintainable at a reasonable cost
See Session 12 Handouts and Presentations:
“Efficient CMP Development”
“Enterprise JavaBeans Patterns”
See Session 12 Sub-Topic 1 Presentation
“Designing Databases for eBusiness Solutions”
31
Four Patterns for Managing Persistence
Pattern Entity Mgt. Uses Uses Entity Session Beans Beans 1. Container-managed Container Yes Yes Entity Beans with Session Beans 2. Bean-managed Bean Yes Yes Entity Beans with Session Beans 3. Entity Beans Only Container Yes No* 4. Session Beans Only N/A No Yes * Session beans are used in this example for complex database interactions, but they do not serve as a front-end for Entity beans. Instead, they access the database directly as an Entity bean would. 32
16 Container-Managed Entity Beans + Session Beans
Entity Uses Entity Uses Management Beans Session Beans Container Yes Yes
Session Entity Client Beans Beans JDBC Database
Application Server
33
Beans-Managed Entity Beans + Session Beans
Entity Uses Entity Uses Management Beans Session Beans Bean Yes Yes
Session Entity Client Beans Beans JDBC Database
Application Server
34
17 Entity Beans Only
Entity Uses Entity Uses Management Beans Session Beans Container Yes No
Entity JDBC Beans Client Database
Session JDBC Beans
Application Server
35
Session Beans Only
Entity Uses Entity Uses Management Beans Session Beans N/A No Yes
Session Client Beans JDBC Database
Application Server
36
18 Performance Characteristics
Pattern Comparison 400 users, 50 iterations, 4 server instances/200MB
8.00 7.00 6.00 5.00 4.00 3.00 2.00 1.00 0.00 Max Avg Min 90th StdDev
Max Avg 90t h Min St dDev
Sessi on Onl y 6.36 0.20 0.15 0.02 0.612 Cont ainer Managed 6.74 0.31 0.79 0.04 0.706 37 Bean Managed 7.02 0.31 0.95 0.04 0.687
Performance Characteristics (continued)
Pattern Comparison 100 users, 50 iterations, 4 server instances/200MB 5.00 4.00 3.00 2.00 1.00 0.00 Max Avg 90th Min St dDev
Max A v g 90th Min StdDev
Entity Only 4.49 0.30 0.35 0.08 0.426 Container Managed 1.52 0.06 0.07 0.04 0.112
38
19 SQL Statements v.s. Finder Methods
SQL vs. Finder Method Comparison (for getting lists of da ta )
10.00 8.00 6.00 4.00 2.00 0.00 Max Avg Min 90th StdDev
Max A v g 90th Min StdDev
SQL 5.54 0.20 0.15 0.04 0.571 Finder Methods 9.99 1.06 2.92 0.05 1.457
39
Summary of Findings
Pattern 1:(better choice)
Great for design and flexibility
Good separation of presentation, data, and business logic
Fast time to market
Pattern 4:
Best for performance and throughput
Pattern 3:
Faster time to market than pattern 1
No need to code session beans
Prohibitive performance cost
40
20 Part III
XML and Database Technology
41
XML & DBMSs Comparison
Both separate data from rendition/presentation info
Similar languages
DBMSs: Forms and Reporting, DDL, DQL, DCL
XML: XSL, XQL, and processing instructions
No DML in XML
XML is paired with a scripting or programming language
Validation capabilities
DBMSs: datatyping, relationship constraints
XML: data type validity and semantic consistency checks
XML can handle data too complex for some databases
XML interchangeable form of data vs. multidatabases 42
21 XML Support for JavaBeans and EJBs
XML and JavaBeans integration
e.g., BML, Coins (http://www.jxml.com), etc.
JavaBeans and EJB state persistence using XML
XML serialization for Java (e.g., Koala, etc.)
XML Application Services as JavaBeans/EJBs
e.g., Parsing, rendering, querying, messaging beans
43
Overview of XML and Database Technology
http://www.rpbourret.com/xml/XMLDatabaseProds.htm#products
XML documents are either data- or document-centric
Categories of XML database software
Middleware (data-centric, requires coding)
XML-Enabled Databases (data-centric, requires coding)
Native XML Databases (data- and document-centric, requires coding)
XML Servers (data-centric, requires coding)
XML Application Servers (data- and document-centric, requires scripting)
Content Management Systems (document-centric, requires configuration)
XML Query Engines (document-centric, requires coding)
Persistent DOM implementations (native XML databases)
http://www.rpbourret.com/xml/XMLDatabaseProds.htm#products
http://www.javaworld.com/javaworld/jw-01-2000/jw-01-dbxml.html
http://www.xhive.com 44
22 Criteria for XML Database Solution
Portability and platform independence
Compatibility with Java technology and SAX/DOM parsers
Compatibility with Servlet/JSP component models
Open source powerful solution
45
Architecture of the XML APIs to DBMSs
46
23 XML Query and XML Query Engines
Most up to date implementation of XML Query Engine
XQEngine (http://www.fatdog.com)
Software AG’s QuiP
Search.jsp SearchBean
XMLs Result SAX Parser Result(XML)
47
Architecture of an XML MOM Application Server
48
24 Sample XML Application Flow
49
Towards XML Model Based Computing
Step 1: Document Object Model
Step 2: XML Data Binding
Step 3: Standard XML Information Models
Step 4: XML Application Services Frameworks
Processing, Rendering, Querying, Secure Messaging
Step 5: XML-Based “Web Object Model”
Web Services Architecture
Step 6: XML Model Driven Architectures (to come)
50
25 Part IV
Conclusion
51
Summary
Technology is moving towards XML Model Based Computing and Model Driven Application Architectures
At the same time, application infrastructures are evolving towards Channel Independent, Web Services and B2Bi-enabled platforms
The Java Framework provides extensive support for database interfacing ranging from programmatic access to container managed persistence
Applying XML to Database Technology allows the viewing of database data as an XML document
XML Query Engines are infrastructure components that support XML Query 52
26 Architecture Frameworks
CORBA & Applets (e.g., VisiBroker, and ORBacus)
RMI-JRMP and RMI-IIOP
Web Servers (e.g., Apache), Servlet & JSP Engines (e.g., Tomcat, JRun, WebSphere Client and Web Containers)
J2EE Application Servers (e.g., WebSphere, WebLogic, JBoss)
J2ME CLDC MIDP/PADP configuration and profiles
XML Parsers (e.g., XercesJ)
XML server-side POP frameworks (e.g., Cocoon 2/XSP)
XML EAI frameworks (e.g., WebMethods), B2Bi, BPM, LE, and EII
IDEs (e.g., JBuilder), and JavaBeans Development Kit (e.g., BDK) 53
Assignment Readings
J2EE: Part II Chap. 6 and 7
Expert One-on-One: Chap. 7, 9, 15
Selected readings mentioned in class or referenced in the handouts
Handouts posted on the course web site
Assignment #5a: (submit report and implementation archive)
Submit project increment 4 focused on J2EE database-related development. Design and develop a three-tier version of your framework-based application that supports the storage of XML data in a back-end database via JDBC.
Project Framework Setup
J2EE IDE: IBM WSAD, WAS, DB2
Java Plug-in, Java Web Start, Apache’s Xerces/Xalan
J2SE 1.3.1, 1.4.0 or 1.4.1 (SDK)
IDE: Eclipse, NetBeans, Sun ONE Studio, JBuilder, Visual Age, Visual Café, Codewarrior, WebGain Studio, Oracle JDeveloper, etc.
Editors: JCreator, UltraEdit, etc.
Visibroker 4.5.1 or BES 5.2 54 RMI-IIOP / Java IDL
27 Next Session: Java Database Technology (Part II)
Review of Session 12 Topics Java Database Technology (continued) Introduction to Web Services and J2EE J2EE Security J2EE Messaging Message Driven Beans J2EE Process Management Java Operating Systems and Networking Technologies Course Material Review Final Exam (Take Home Project)
55
28