Java Database Technologies (Part I)
Total Page:16
File Type:pdf, Size:1020Kb
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) <?xml version="1.0"?> <!DOCTYPE ejbmaker SYSTEM "ejbmaker.dtd"> <ejbmaker> <!—default attributes for beans --> <transaction-attr>TX_REQUIRED</transaction-attr> <isolation-level>SERIALIZABLE</isolation-level> <run-as-mode>SPECIFIED_IDENTITY</run-as-mode> <re-entrant>false</re-entrant> <!—A Simple Account CMP entity EJB --> <bean name = "Account" type = "entity"> <persistent_field dt="int" col_dt="INTEGER"> ACCTNUMBER </persistent_field> <persistent_field dt="java.lang.String" col_dt="VARCHAR(13)"> SSN </persistent_field> <persistent_field dt="double" col_dt="DOUBLE"> BALANCE </persistent_field> <finder_method name="findNegativeAcct"> <sql> SELECT * FROM EJB.ACCOUNTBEANTBL WHERE BALANCE < 0 </sql> </finder_method> </bean> 20 </ejbmaker> 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