Title: Jerry Held
1(No Transcript)
2TopLink Now and in the future, O-R Mapping
Product of Choice
- Doug Clarke
- Principal Product Manager, Oracle9iAS TopLink
- Oracle Corporation
3Speakers Qualifications
- Doug has a decade of experience in OO Persistence
- Development, Consulting Training
- Product Manager for TopLink product
4Underestimation
Managing persistence related issues is the most
underestimated challenge in enterprise Java today
in terms of complexity, effort and maintenance
5Agenda
- Ways to access RDB from J2EE
- Impedance Mismatch
- TopLink Overview
- TopLink in Development
- Runtime Architecture
- O-R Mapping Flexibility
- Queries
- Transactions
- Caching
- Locking
- Performance Features
- TopLink Roadmap
6J2EE Access of Relational Data
- Direct JDBC
- Direct SQL calls
- Use rows and result sets directly
- Persistence Layer
- Accessed as objects or components
- Transparent that the data is stored in RDB
- Persistence layer in middle tier handles
object-relational mapping and infrastructure - Required if doing business logic in the middle
tier! - Focus of this Session
7Direct JDBC
- JDBC is NOT a persistence framework
- JDBC is a database connection utility
- Ok for Window on data style application
- Ok when business logic is entrenched on database
- J2EE becomes a presentation layer
JDBC
SQL
rows
8Object Persistence Layer
- Abstracts persistence details from the
application layer
J2EE Web Services
object-level querying and creationresults are
objects
object creation and updates through
object-level API
Objects
Objects
JDBC
results arereturned as raw data
API uses SQLor databasespecific calls
SQL
rows
9Problem
- Building Java applications with relational
databases is a VERY challenging and labor
intensive problem to solve - Fundamentally different technology
- Different skill sets
- Different staff/ownership
- Different modeling and design principles
?
Differences must be resolved to fulfill business
requirements
10Impedance Mismatch
11Object Level Options
- Depends on what component architecture is used
- Entity Beans BMP Bean Managed Persistence
- Entity Beans CMP Container Managed Persistence
- POJO Plain Ol Java Objects via Persistence
Layer - May be home-grown following DAO Data Access
Object patterns - May use JDO Java Data Objects
- May use off the shelf products
12J2EE Architectures
- J2EE Architecture Options
- Servlets
- JSP
- Session Beans
- Message Driven Beans
- Web Services
- Bottom Line Java application needs to access
relational data somehow
13Oracle9iAS TopLink Solution
- Oracle9iAS TopLink provides a proven, powerful
out of the box solution to address the
diversity between Java and Databases
Oracle9iAS TopLink
14TopLink in Development
TopLink Mapping Workbench
TopLink Meta-Data(XML)
IMPORT (.class)
IMPORT
GENERATE
GENERATE (.java)
Relational database (schema)
Java IDE
Java classes
15TopLink Runtime Architecture
16Basic J2EE Persistence Checklist
- O-R Mappings
- Runtime Components
- O-R Mapping Flexibility
- Queries
- Transactions
- Caching
- Locking
- Performance Features
17Data and Object Models
- Rich, flexible mapping capabilities provide data
and object models a degree of independence - Otherwise, business object model will force
changes to the data schema or vice-versa - Often, J2EE component models are nothing more
than mirror images of data model or vice versa
NOT desirable
18Mapping Tools
- The underlying mapping flexibility is very
important
19Simple Object Model
11 Relationship
20Typical 1-1 Relationship Schema
21Other possible Schemas
22Even More Schemas
CUST
CUST_CREDIT
ID
NAME
ID
C_RATING
23Benefits of Good O-R Mapping
- Flexible - Just showed nine valid ways a 1-1
relationship could be represented in a database
(Most persistence solutions will only support
one) - Without good support, designs will be forced
- Comprehensive support for custom types,
inheritance, - Simple mapping for identity management
- Custom type support
- Non-intrusive/transparent to the business model
developer
24MORE than just Mapping
- Querying
- Transactions
- Caching
- Concurrency
- Performance
25Queries
- Java developers are not usually SQL experts
- Maintenance and portability become a concern when
schema details hard-coded in application - Allow Java based queries that are translated to
SQL and leverage database options
employee.get(manager).get(address)
someAddress
Generates
SELECT FROM EMP t1, EMP t2, ADDR t3 WHERE
t1.MGR_ID t2.EMP_ID AND t2.ADDR_ID t3.ADDR_ID
AND t3.ADDR_ID ltsomeAddress.idgt
26Query Features
- Ability to trace, profile, and tune SQL
- Ad hoc SQL where necessary
- Must be able to leverage database abilities
- Outer joins
- Nested queries
- Stored Procedures
- Database Specific Optimizations (Oracle Hints)
- Choice of query language SQL, Stored procedures,
EJBQL, or TopLinks Object expressions - In-Memory querying and transaction conformity
27Transaction Management
- J2EE apps typically support many clients sharing
small number of db connections - Ideally would like to minimize length of
transaction on database
Begin Txn
Time
Begin Txn
Commit Txn
Commit Txn
28Support for Referential Integrity
- Java developers manipulate object model in a
manner logical to the business domain - May result in ordering of INSERT, UPDATE and
DELETE statements that violate database
constraints - Persistence layer should automatically manage
this and allow options for Java developer to
influence order of statements
29Object Cache
- Cache your business objects
- Improved performance by reducing reads
- Configurable
- Support for clustered caches
- Concurrency support for multi-client reading and
writing
30Caching in the real world
- Any application that caches data, now has to deal
with stale data - When and how to refresh?
- Will constant refreshing reduce performance?
- Problem is compounded in a clustered environment
- App server may want be notified of database
changes - TopLink supports all of these cases
31Caching
SQL Query (if desired)
OO Query
Results(s)
NO Build bean/object from results
Does PK for row exist in cache?
Return object results
YES Get from Cache
32Concurrency Locking
- J2EE Developers want to think of locking at the
object level - Databases may need to manage locking across many
applications - Persistence layer or application server must be
able to respect and participate in locks at
database level
33Optimistic Locking
- DBA may wish to use version, timestamp and/or
last update field to represent optimistic lock - Java developer may not want this in their
business model - Persistence layer must be able to abstract this
- Must be able to support using any fields
including business domain
34Pessimistic Locking
- Requires careful attention as a JDBC connection
is required for duration of pessimistic lock - Should support SELECT FOR UPDATE NOWAIT
semantics - Consider Application level pessimistic locking
Begin Txn
Time
Begin Txn
Pess Lock
Commit Txn
Commit Txn
35Performance Lazy Reads
- J2EE Applications work on the scale of a few
hundreds of megabytes - Relational databases routinely manage gigabytes
and terabytes of data - Persistence layer must be able to transparently
fetch data just in time
36Just in Time Reading Faulting Process
Accessing relationship for first time
Customer
Proxy
Get related object based on FK
Plug result into Proxy
SQL if not cached
Check Cache
Orders
Orders
Orders
37Object Traversals
- Even with lazy reads, object traversal is not
always ideal - To find a phone number for the manufacturer of a
product that a particular customer bought, may do
several queries - Get customer in question
- Get orders for customer
- Get parts for order
- Get manufacturer for part
- Get address for manufacturer
- Very natural object traversal results in 5
queries to get data that can be done in 1
38N1 Reads Problem
- Many persistence layers and application servers
have an N1 reads problem - Causes N subsequent queries to fetch related data
when a collection is queried for - A side effect of the impedance mismatch and poor
mapping and querying support in persistence layers
39N1 Reads Problem
Pool of Created Objects or Beans
C
C
C
C
findByCity()
Returns collection
findByCity()
n
For each Customer Fetch their Address
n
Container returns results
If Address had related objects, they too may be
fetched 2n1 Reads!
40N1 Reads
- Must have solution to minimize queries
- Need flexibility to reduce to 1 query, 11 query
or N1 query where appropriate - 1 Query when displaying list of customers and
addresses known as a Join Read - 11 Query when displaying list of customers and
user may click button to see addresses known as
a Batch Read - N1 Query when displaying list of customers but
only want to see address for selected customer
41Performance and Tuning Options
- Automatic change detection
- Caching policies and sizes
- Parameterized SQL
- Pre-allocation of sequence numbers
- Cache synchronization support
- Optimistic, Pessimistic locking
- Joining object retrieval optimization
- In memory querying
- Dynamic queries
- Query optimization
- Minimal Writes, Updates
- Batch Reading, Writing
- SQL ordering
- Transformation support
- Existence checks
- Stored procedures
- Read Lock Support
- Statement Caching
- Scrolling cursors
- Partial Attribute Queries
- Just in Time reading
AND MUCH MORE!
42Why is TopLink the O-R leader?
- Productive development tools
- Extremely flexible O-R mappings
- Choice and performance in querying
- Scalable cache and transaction framework
- Powerful performance tuning options
- Strong J2EE support and integrations
- Complete architecture and database flexibility
- Award winning product based on years of real
world application development and backed by
worlds leading enterprise software company.
43Whats Next TopLink Roadmap
- Maintain leadership in O-R persistence
- Expand data source support
- EIS through J2EE Connector Architecture
- Object-to-XML
- Maintain current with standards and provide
functionality demanded by our customers
44TopLink XML
- XML documents can be represented at different
levels of abstractions in J2EE applications - Parsed document (DOM, SAX ) - parser
- Unmanaged Java objects from non-transactional
data source data converter - Managed Java objects from a transactional data
source persistence manager
453 Levels of XML Representation
Unmanaged Object
DOM
Managed Object/EJB
Persistence Manager
O-X Data Converter
XML Parser
XML Document
JDBC
J2C
File
XDB
EIS
Web Service
BPM
JMS
46Impact on J2EE Integration Solutions
- This technology will be critical for many J2EE
applications accessing EIS systems via JCA
resource adapters - XML based adapters will outgrow proprietary data
formats - 80 of the worldwide data resides on
mainframes. Gartner - Without it, developers will have to work with low
level XML documents and manually code persistence
manager functionality
47Benefits of XML/JCA Support
- Easier to adopt and integrate web services,
disparate data and legacy applications. - Abstracting data details provides flexibility and
portability. - Increased developer productivity as they focus on
building applications not infrastructure. - Single abstraction layer to access heterogeneous
data sources. - Optimized performance and scalability.
- Leverage existing architecture and developer
skills base
48Summary
- TopLink is clearly leader in O-R mapping
- Many exciting directions for the future
49If You Only Remember One Thing
When choosing a persistence layer, Pick one that
maximizes your flexibility across all the issues
outlined here today!
50A
51(No Transcript)